[ACCEPTED]-Regex - Match a Pattern Before a Character-regex
Accepted answer
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})(?==)
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 "=".
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
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.