How can I match a greedily quantified string of non-'[' characters which doesn't contain the string '->' anywhere inside it?
-
03-07-2021 - |
Pergunta
This is sort of a starting point, although I don't think it actually covers the scenario, or if it does, it's confusing me too much for me to wrap my head around how to apply it to what I need. I wouldn't know whether to use .
or .....
and then I'm not sure how I would achieve the greedy, imprecise quantification.
Regexes make my head spin...
Solução
Try this:
((?!->)[^\]])+
The pattern first looks ahead to check that there's no "->"
(the (?!->)
part), and then matches any char other than a "]"
. This is then repeated once or more.
You may want to "anchor" your pattern to validate the entire input string:
^((?!->)[^\]])+$
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow