Determine if word from alteration list exists and set next condition accordingly

A not-so-clear title, I know...

Here is what I'm looking for in RegEx (C#): I have two alteration lists, say (aa|bb) & (xx|yy). I want to set the second list's prefix according to the whether there is an item from the first list before it.

For example, if there is a string from the first list, then the second list should be prefixed by j or p.

If not - it should be prefixed by o or t.

Some samples:

aa jxx <- Match
aa pyy <- Match
bb nxx <- Does not match
oxx <- Match
jxx <- Does not match

How can I achieve that in RegEx?

Thanks!

Answers


Try this :

(?:[ot](xx|yy))|(?:(aa|bb)\s[jp](xx|yy))

Demo :

http://regex101.com/r/hH0zO6


Hint : All I did was to "translate" your specification into regex. :-)


Try this one:

^((aa|bb)\s+[jp](xx|yy))|([ot](xx|yy))$

Basically it has two main regex condition separated by a pipe(|). ((aa|bb)\s+[jp](xx|yy)) and ([ot](xx|yy))


Need Your Help

PHP Form SQL Format Error

php html database forms

I am trying to make a simple form that checks based on the correct email. If the email is correct, it then updates the database with the new time. When I run it, I get a format error.. I am not an ...