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 match? Regex: Match the string between ;string; excluding ;"string";

I have a file which has multiple rows like below:

"47058";"post";keyword1;"Why is x bad?";"https://example.com/why-is-x-bad/"
"47059";"post";keyword2;"Why is y bad?";"https://example.com/why-is-y-bad/"

I want a regex that only matches keyword1 and keyword2, basically any string inside ;; but excluding ;"";

Goal: Add "" around keyword1 and keyword2

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

>Solution :

Basically, you want all matches where the keyword is just a set of letters surrounded by semi-colons (;) not surrounded by inverted commas(") followed by semi-colons.

Assuming the keyword only contains letters and nothing else.

You can use regex of ;[a-zA-Z]+;

Tested on https://www.regextester.com/

enter image description here

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