Reputation: 43
My input string is:
/234243/source_path/a/b/c.test
or something like:
/234243/source_path/a/b/c.test/check_w123
I want a regex to match substrings starting with source
and check
with the result like:
source
: source_path/a/b/c.test/
check
: check_w123
using a regex like /(?<source>source.*)(?<check>check.*)/
without ?
in the last group.
My regex is:
/(?<source>source.*)(?<check>check.*)?/
My Result is:
source
: source_path/a/b/c.test/check_w123
check
: nil
Upvotes: 0
Views: 299
Reputation: 174706
Just turn .*
inside the first source group into it's non-greedy form. And don't forget to add end of the line anchor.
(?<source>source.*?)(?<check>check.*)?$
Upvotes: 2
Reputation: 67968
(?<source>source.*?(?!.*\/))(?<check>check.*)?
Try this.See demo.
https://regex101.com/r/rU8yP6/11
Upvotes: 0