java - Regex Match word that include a Dot -
i have question have sentence example:
"halloanna daveca.nn dave anna ca. anna"
and wanna match single standing "ca." .
my regex :
(?i)\b(ca\.)\b
but doesn't work , don't know why. ideas ?
//update
i excecute with:
testsource.replaceall()
and with
pattern.matcher(testsource).replaceall().
both doesn´t work.
you should use this:
pattern.compile("(?i)\\b(ca\\.)(?=\\w)").matcher(a).replaceall("some text");
which if omit java escapes gives regex: (?i)\b(ca\.)\w
.
every \
in normal regex has escaped in java - \\
.
also, before word have word boundary (\b
), applies part in string have change whitespace alphanumeric character or other way around. in case have dot, not alphanumeric character, can't use \b
@ end. can use \w
means non-word character following dot. use \w
need ignore in capture group (so won't replaced) - (?=
.
another issue used .
, matches character, want match real dot, have escape - \.
, in java string becomes \\.
.
Comments
Post a Comment