i need a regex able to capture the word after ‘cat ‘ (without taking ‘cat’)
For example:
In ‘cat gifi’ i want to capture ‘gifi’
I tried : /cat s+(w+)/
I also search on the internet and even ask to ChatGPT
Can you help me please ?
i need a regex able to capture the word after ‘cat ‘ (without taking ‘cat’)
For example:
In ‘cat gifi’ i want to capture ‘gifi’
I tried : /cat s+(w+)/
I also search on the internet and even ask to ChatGPT
Can you help me please ?
2
Answers
You can use a lookbehind assertion,
(?<=...)
to assert that something needs to be present for the regex to match (here,cats+
), without making it part of the actual match result.For example:
will log
["gifi", "gifi"]
(the entire regex match isgifi
and the only capture group isgifi
).add new lines, tabs etc to or condition in bracket if need be. I think this should work though.