0

I am using

^(?i)(?=.*\bWORD_TO_FIND\b).*$

In this specific case I am trying to match "S.A.M."

This way it works:

^(?i)(?=.*\bs.a.m\b).*$

This way it doesn't:

^(?i)(?=.*\bs.a.m.\b).*$

Why does that fullstop brakes the match?

user2468425
  • 419
  • 2
  • 13
  • You don't need the lookahead assertion for this. And you should regex quote the find word(s). And you should use a boundary with qualification. You could use a conditional boundary `"(?i)^.*(?(?=\\w)\\b)(?:" + regexQuote(text) + ")(?(?<=\\w)\\b).*$"` or, the best way is to use a whitespace boundary `"(?i)^.*(?<!\\S)(?:" + regexQuote(text) + ")(?!\\S).*$"` –  Nov 18 '15 at 17:10

1 Answers1

1

That is because of \b or word boundary.After . there is no \b or word boundary but after m there is.

^(?i)(?=.*\bs\.a\.m\.\b).*$

                    ^^
                  Here no word boundary so assertion or lookahead fails.

You should also be escaping . if you want to match .

vks
  • 67,027
  • 10
  • 91
  • 124