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 to match character when the character to the left is not \

I have a string that I would like to return: hello\'world from the following string: 'hello\'world'

My regex pattern that currently does not work is the following: '[^']+'

This pattern gets all text that is within two single quotes. However, in my example, I would like it to ignore the single quote that has the \ character before it. Currently, my pattern above would return hello\ and another match as world

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

How can I achieve this desired result?

>Solution :

The following literally matches a quote (') then groups anything that follows ((.*)) that is followed by a quote (') not preceded by a slash (negative lookbehind: (?<!\\))

'(.+)(?<!\\)'
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