I have data that looks this:
Key: [36;1m2848761038914979188[0m
Partition: 0
Offset: 33443
Timestamp: 2022-09-27 15:57:57.693 -0400 EDT
Key: [36;1m2039734487331374643[0m
Partition: 0
Offset: 33444
Timestamp: 2022-09-27 17:26:31.477 -0400 EDT
Key: [36;1m2868926969028805951[0m
Partition: 0
Offset: 33445
Timestamp: 2022-09-27 17:41:31.473 -0400 EDT
Key: [36;1m2936812472746641386[0m
Partition: 0
Offset: 33446
Timestamp: 2022-09-27 18:02:23.803 -0400 EDT
I want a regex to match EVERYTHING BUT the numbers in between [36;1m
and [0m
. How do I capture this? I don't want to regex match the numbers... I want everything BUT the numbers (I want this so I can delete everything but the numbers in my text editor).
this regex isn't good enough: (^|\[)(?!36;1m)[^\[]*
:
CodePudding user response:
Aren't you overcomplicating this? It sounds like this is enough:
\[36;1m(\d )\[0m
CodePudding user response:
You can use this regex:
[^[] (\[36;1m|$)|\[0m
with the global
flag set.
Explanation:
[^[]
- match one or more characters, that are NOT [
.
(\[36;1m|$)
- create a group that matches EITHER
[36;1m
OR
end of string ($
).
|\[0m
- OR
match [0m
.
I have created this test page for you (uses javascript, but should work in all regex flavors: JSRegExpBuilder