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

How do I not include the first part of a Text String in my Regex?

I am using the Text String cdblt31.funtimes.com and DO NOT want to include "cdbltl31" in my Regex. How do I not capture that part?

>Solution :

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

This pattern will match all except the part you don’t want.

\.\w+\.\w+$
  • First is a point which we have to escape as \. because it has a special meaning in regex.
  • Then \w matches any word character (basically letters and numbers).
  • + means one or more times ie. any number of repeats (except 0).
  • We then re-use the same symbols \.\w+ because we want to match a second point and more word characters.
  • Finally $ means the end of the line.
    We could also write
(\.\w+){2}$

I’ll let you look up the new characters.

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