Regular expression to match condition of character if exists should always be followed by a pattern

regular expressions

I need a regular expression with the condition that ..if there is an occurrence of character | one time ;the pattern immediately following is ARGS or URL

For example

abcd
ab|ARGS
cd|URL

etc is valid

abcd|
ab||ARGS
ab|cd

etc are invalid (should not match )

Best Answer

Very old post, but it still may help someone.

The following regex worked for me:

^[^\|]*(\|ARGS|\|URL)?[^\|]*$

(test it on regexr.com)

I added the | to the ARGS and URL string, and forbid them before or after.