Search code examples
delimiterpcre

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.


Solution

  • 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