![]() ![]() will do that only once, so it is wrapped in a group, and repeated zero or more times: ((?!hede).)*. So, in my example, every empty string is first validated to see if there's no "hede" up ahead, before a character is consumed by the. Look-arounds are also called zero-width-assertions because they don't consume any characters. (dot) will match any character except a line break. looks ahead to see if there's no substring "hede" to be seen, and if that is the case (so something else is seen), then the. So a list of n characters will have n+1 empty strings. Before, and after each character, there's an empty string. If the DOT-ALL modifier is not available, you can mimic the same behavior with the character class : /^((?!hede))*$/Ī string is just a list of n characters. (where the /./ are the regex delimiters, i.e., not part of the pattern) As mentioned, this is not something regex is "good" at (or should do), but still, it is possible.Īnd if you need to match line break chars as well, use the DOT-ALL modifier (the trailing s in the following pattern): /^((?!hede).)*$/s The regex above will match any string, or line without a line break, not containing the (sub)string 'hede'. You can mimic this behavior by using negative look-arounds: ^((?!hede).)*$ The notion that regex doesn't support inverse matching is not entirely true. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |