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: Curly braces in reverse? Match X characters before a string?

In the following example, how could I match an X number of characters before and after (myword1 myword2):

word1 word2 word3 myword1 myword2 word4 word5 word6

Matching after is easy with curly braces: (myword1 myword2)(.+?){10} – but how could I match the preceding 10 characters before (myword1 myword2)?

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 tried (.+?){10}(myword1 myword2), but that exceeded the memory limit.

>Solution :

You could use:

.{10}: match any character 10 times

So your expression becomes:
.{10}(myword1 myword2)

And the match is: rd2 word3 myword1 myword2

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