I have the regex string and I want to classify, is this regex has fixed prefix or no.
For example:
abcdef.*g[0abc]{0,5}hi
has prefix abcdef
]1234vac.*12345
has prefix ]1234vac
(abc)+123
has prefix abc
but
[A-z]+12345
doesn't has fixed prefix (it starts from unknown number of symbols from set A-z)
Am I truly understand that this problem will not be solved in a general form?
Try this RegEx:
^(
( # GENERAL before . (Dot)
(?!\w+\?) # DO NOT MATCH if contains ?
[\w\]\)]+ # Word, ] or ) characters 1 or more times
)|
(?:\((\w+)\))| # Words in between BRACKETS ()
( # BEFORE . (Dot) with ?, * or +
[\w\]\)]+ # Select Characters
(?![?*+]) # DO NOT select last character if there is ?, * or + after it
)
)
Live Demo on Regex101
Tell me any other examples that do not work and I'll change this. I have however tested on all the examples in your question, and comments
Also, how is it even possible to come up with a question this complicated! ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With