0

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 )

Anoop P Alias
  • 347
  • 4
  • 7
  • And what have you tried so far, what regex resources have you already checked? – Colyn1337 Nov 11 '15 at 15:05
  • Tried .*\|(ARGS|URL).* which doesnt match abcd though – Anoop P Alias Nov 11 '15 at 15:09
  • @AnoopPAlias If I read your requirements, it shouldn't match abcd| ? (And your valid examples contradicts your written requirements) – Reaces Nov 13 '15 at 09:03
  • @Reaces - Yes it shouldnt match abcd| .In the example the first three are the matching ones and the 2nd set of 3 are the invalid ones or that should not match . abcd1 comes in 2nd set . – Anoop P Alias Nov 13 '15 at 13:55

1 Answers1

2

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.

Tobias
  • 1,236
  • 13
  • 25