[ACCEPTED]-Regex - Match a Pattern Before a Character-regex

Accepted answer
Score: 33

What you want is called a zero-width, lookahead 2 assertion. You do:

(Match this and capture)(?=before this)

In your case, this would 1 be:

([A-Z^]{1,3})(?==)
Score: 31

You need a positive lookahead assertion:

([A-Z]{1,3})(?==)

0

Score: 4

The following will group everything before 4 the "=" and everything after.

([^=]*)=([^=]*)

it reads something 3 like this:

match any amount of characters 2 thats not a "=", followed by a "=", then 1 any amount of characters thats not a "=".

Score: 0

You can also put the equals sign in a non-capturing 5 parans with (?: ... )

([ADM]{1,3})(?:=)

It's been a bit since 4 I did this chapter of the book but I think 3 that since you need both parts of the expression 2 anyway, I did a split on the = resulting 1 in myArray[0] == M, myArray[1] == A

More Related questions