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 – match behind an optional character

I want to match a string that has more than 3 characters and combine with positive look behind an optional character (/).
From the input:

100/ABC-12345 10
ABCD
ZZZ

I need to retrieve:

ABC-12345 10
ABCD

I can match them separately but cannot combine them. See my current regex:

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 :

You may use:

(?<=/|^)\w[\w-]{3,}

Updated Regex Demo

Positive lookbehind (?<=/|^) asserts presence of / or start of line behind current position and \w[\w-]{3,} matches at least 4 of word or hyphen characters where first character must be a word character.

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