Link to home
Start Free TrialLog in
Avatar of peispud
peispudFlag for Canada

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
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well, your regex is overly complex for your given requirements. You don't need to match the rest of the string. Just your desired one.

/P\.E\.I\.

Open in new window


User generated image
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
Avatar of peispud

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.  

Avatar of louisfr
louisfr

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.