For example: the line - "all this is here to here, and then there is a lot more to here". The substring to which you need to bring everything up to here, you need to get everything that's it.
- Yeah. And what do you want to tell us about this regular expression? You have no question in the question itself. - Nick Volynkin ♦
- @NickVolynkin, everything is fine in the question. - Qwertiy ♦
|
3 answers
The problem is solved using the following regular expression (PCRE):
(.*?)досюда
In the first match (Match 1) will be the required substring.
Attention should be paid to the "lazy" quantifier ( .*?
). If he were ordinary, i.e. greedy ( .*
), the result would be slightly different than expected. Greedy Quantifier for String
"все вот это досюда, а дальше там еще много всего досюда"
will give a match
"все вот это досюда, а дальше там еще много всего "
while the "lazy" will give quite the expected result:
"все вот это "
|
the most logical solution is to delete the desired word and all characters after it:
s/досюда.*//
in the line will remain only what is required.
|
"any text any text any text<stop>other text other text ...".match(/[\s\S]*?(?=<stop>)/)
|