I need a regular expression that matches letters and digits, but doesn't match the sequence "00".
e.g. "hello00world00number001" should match: "hello", "world", "number" and "1".
I tested without success:
(?:[\w](?<!00))+
Edit: "hello000world0000number000001" must be separated into: "hello0" "world" "number0" and "1"
Input string: hello000world0000number00000100test00test20
Splitting by 00
alone will generate empty matches if a series like 0000
is encountered:
Output: hello/0world//number//01/test/test20
To work around this let's enclose 2 zeroes in a group:
RegEx: (00)+
- last uneven 0
in the series goes to the next match - live demo
Output: hello/0world/number/01/test/test20
Use a negative lookahead:
RegEx: (00)+(?!0)
- keep the first 0
in an uneven series in the first match - live demo
Output: hello0/world/number0/1/test/test20
00
only /([a-z0-9]+?)(?:(?:00)+|$)/gi
- live demo
/([a-z0-9]+?)(?:(?:00)+(?!0)|$)/gi
- live demo
str = "hello00world00number001"
str.split("00")
Why would this not work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With