Reputation: 1035
I'm new to regex and need practice some test I have following string:
zwr ^test1\0asdnasndzwr ^test2\0asdnk\0
I need to grab : zwr ^test\0
and zwr ^test2\0
I'm trying using following pattern but it match whole of string
^zwr.*\\0$
https://regex101.com/r/eO6zD9/1
Please help me correct it Thanks
Upvotes: 1
Views: 33
Reputation: 1212
zwr.*?\\0
first remove ^
and $
if you global match
second use a non-greedy match .*?
by the way,your regex101's link have an empty line
Upvotes: 1
Reputation: 5119
I believe this should do the trick:
zwr\s*\^test\d*\\0
https://regex101.com/r/lT6iD5/3
You were using ^
and $
which means the entire string can only contain the matching text, not allowing for repetitions, so I removed that. You also had .*
which will greedily match everything after the first zwr
.
I made the pattern more explicit in matching the target strings, but with flexibility around what digit.
Upvotes: 1