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: a pattern that's start with a word and finish with ":"

I would like to have the correct regex code for patterns that are like this one, it starts with words until this symbol ":" example :
"This is: a pattern"
the regex code that I want has to match from only the starting words to the symbol ":" ( for the example that I provided, I want to match "This is")

>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

Something like this should work

r'\b[^:]*(?=:)'

Details:

  • \b asserts that the match must occur on a boundary of a word (i.e asserts position at the edge of a word).

  • [^:]* matches zero or more repetitions of characters other than the :.

  • (?=:) is a positive lookahead assertion (checks if we have a : but does not actually consume it).

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