Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex: Any pattern present more than once should not be a match

String to be matched: first-3-days

Regex: first-[3,6]-days

This Regex matches the string as expected. But, if there are any other characters before or after the given string, that will be an invalid match for me. For instance,

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

hellofirst-3-days – is invalid match

first-3daysfirst-3-days – is invalid match

Any hints please.

>Solution :

I guess you want to match 3 or 6 and not ,. If that is true, you should use [36] and not [3,6]

You can use word boundaries:

\bfirst-[36]-days\b

Or if your input string should start from first and end with days you can use start/end string specifiers, e.g.:

^first-[36]-days$
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading