want to match word i.v.
case insensitive
have pattern
(?i)\\bi\\.v\\.
but want a word boundary on the end
the abov
You seems to be very confuse with word boundaries and greedy notions. The best thing you can do is to go to these addresses:
http://www.regular-expressions.info/repeat.html
http://www.regular-expressions.info/wordboundaries.html
When you will read these explanations, I am sure you will think that your problem was ridiculous.
\b
only matches between an alphanumeric character and a non-alphanumeric character (or the start/end of string). Therefore, it doesn't match after a .
, unless an alphanumeric character immediately follows that dot.
If your intent is to make sure that no non-whitespace character follows after the dot, then you can specify that using a negative lookahead assertion:
(?i)\bi\.v\.(?!\S)
(?!\S)
means "Assert that the next character is not a non-whitespace character".
This may sound a bit convoluted - why the double negative? Why not (?=\s)
which means "Assert that the next character is a whitespace character"? Well, there is a subtle difference: The second version requires a whitespace character to be there; that means the regex would fail to match at the end of the string. The first regex handles that corner case as well.
If you generally want the concept of "word boundary" to mean "space-delimited", then you need to replace the first \b
as well:
(?i)(?<!\S)i\.v\.(?!\S)
or the regex will match sam.i.v.
which you don't seem to want it to.
About your current regex:
You don't need to have \b
after dot since dot is not considered a word character but of course dot needs to be escaped:
(?i)\bi\.v\.
But you do need \b
before i
to make sure it doesn't match e.g. hi
EDIT: (Based on your further edits)
Try this regex:
(?i)\bi\.v\.(?=\s|$)