How can I catch an arbitrary string between defined words using regular expressions in .Net, e.g. @”…DEFINED_WORD1 some_arbitrary_string DEFINED_WORD2…”? Unfortunately my experiments with “(?=)” and other patterns are unsuccessful 🙁
How can I catch an arbitrary string between defined words using regular expressions in
Share
This will catch anything between the words, as long as there’s a space after the first word and before the second. If there are multiple occurrences of
WORD2afterWORD1, the first one will be considered.This is the same, but doesn’t require spaces (e.g.
"WORD1, some string WORD2"will match):This will start from the first
WORD1and go on until the lastWORD2:Depending on the details of your case, this may be cleaner and easier without regular expressions.