I have the following regexp:
/^(?:(?:>|<)?[a-zA-Z]+(?:(?:\+|-)\d*\.?\d*(?:em)?)?)(?:<[a-zA-Z]+(?:(?:\+|-)\d*\.?\d*(?:em)?)?)?$/
Which you can think about like this:
^
(?:
(?:>|<)?
[a-zA-Z]+
(?:(?:\+|-)\d*\.?\d*(?:em)?)?
)
(?:
<
[a-zA-Z]+
(?:(?:\+|-)\d*\.?\d*(?:em)?)?
)?
$
It is effectively the same pattern repeated once or twice with a small difference. The core of each pattern is one or more letter [a-zA-Z] followed by an optional minus or plus and a numeric value possibly followed by em. The first instance can start with either < or > and the second instance can only start with <.
So the following are all valid:
`alpha`,
`alphaBravo`,
`alphaBravoCharlie`,
`>alpha`,
`<alpha`,
`>alpha+10`,
`<alpha+10`,
`>alpha+1.5`,
`<alpha+1.5`,
`>alpha-10`,
`>alpha-10`,
`>alpha-1.5`,
`>alpha-1.5`,
`>alpha+10em`,
`<alpha+10em`,
`>alpha+1.5em`,
`<alpha+1.5em`,
`>alpha-1.5em`,
`>alpha-1.5em`,
`alpha-50em<delta-100em`,
`alpha-50em<delta+100em`,
`>alpha-50em<delta+100em`,
My problem is that if the first instance starts with a < then the second instance shouldn't be allowed, so the following should be invalid:
<alpha<bravo
Is it possible to add this restriction to the regexp?
The two approaches I can think of are:
- Check the first character and make the second instance invalid if it is
< - Check if
<has already ocurred in the string (or if<occurs again in the string) and if so, make the second instance invalid.
However I'm not sure how to implement either of these approaches here.