peispud
asked on
Regex criteria is not quite right.
Hi
I am testing on Regex101.com
The regex criteria is /,\s?\b(pe|nb|ns|nf|P\.E\.I\.)\b/gi
The test string is ,PE , pe,nf, nf, NF, P.E.I.
But I can't get a match on P.E.I. unless I add another character (letter or number etc but not a period) to the end of the test string.
Any help would be appreciated
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Please clarify, why the marked post is the answer. The used regex is unnecessarily complex to match "P.E.I." according to your description.
or
/,\s?\b((?:pe|nb|ns|nf)\b| P\.E\.I\.\ B)/gi
/,\s?\b((?:pe|nb|ns|nf)\b|
ASKER
Thank you ste5an .
I did appreciate your reply.
As I read my question again, I admit that my question was not clear.
Your answer was a correct answer for my question.
I apologize for my error.
I did appreciate your reply.
As I read my question again, I admit that my question was not clear.
Your answer was a correct answer for my question.
I apologize for my error.
As for why "P.E.I." was not matched, it's because \b matches at a word boundary. That is, between a word character (letter, digit, underscore) and a non-word character.
Open in new window