user1228352
user1228352

Reputation: 569

PCRE regex for string with delimiter

I want to construct a PCRE regex for following kind of path string:

/root/product/db.main;/root/product/db.part

Please note that there are only two path strings separated by semicolon, that's it.

I was thinking of something like this: [ \t]*([\/\w ._-];+) but it doesn't seem to work.

Any suggestions?

Thanks in advance.

Upvotes: 0

Views: 182

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 520938

Try this regex pattern:

^(?:\/\w+)+(?:\.\w+)?(?:;(?:\/\w+)+(?:\.\w+)?)+$

This matches two or more paths, separated by semicolons. If you only want to match exactly two paths, then use this:

^(?:\/\w+)+(?:\.\w+)?(?:;(?:\/\w+)+(?:\.\w+)?)$

Demo

Upvotes: 1

Related Questions