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 write a RegEx that starts reading from behind?

I have a series of words I try to capture.

I have the following problem:

  • The string ends with a fixed set of words
  • It is not clearly defined how many words the string consists of. However, it should capture all words that start with a upper case letter (German language). Therefore, the left anchor should be the first word starting with lower case.

Example (bold is what I try to capture):

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

  • I like Apple Bananas And Cars.

  • building houses Might Be Salty + Hard said Jessica.

This is the RegEx I tried so far, it only works, if the "non-capture" string does not include any upper case words:
/(?:[a-zäöü]*)([\p{L} +().&]+[Cars|Hard])/gu

>Solution :

Use \p{Lu} for uppercase letters:

(?:[\p{Lu}+()&][\p{L}+()&]* )+(?:Cars|Hard)

See live demo (showing matching umlauted letters and ß).

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