regex:all_text_not_containing
Table of Contents
Regex - All Text Not Containing
Text that does not contain ~
[^~\x22]+
Match anything except \n
.*
Match strings that do not start with a sequence
Ignore strings that start with the label “abc_”.
Use a negative look-ahead assertion:
^(?!abc_).+
Or, use a negative look-behind assertion:
(^.{1,3}$|^.{4}(?<!abc_).*)
Or, use plain old character sets and alternations:
^([^a]|a($|[^b]|b($|[^c]|c($|[^_])))).*
Match strings that do not end in particular sequence
Use a negative lookbehind assertion:
^[/\w\.-]+(?<!\.html)$
or, use a lookahead:
^(?!.*\.html$)[/\w\.-]+$
or, another use of a lookahead assertion:
/((?!\.html$)[/\w.-])+/
NOTE:
- ( - Start a group for the purposes of repeating.
- (?!\.html$) - Negative lookahead assertion for the pattern /\.html$/.
- [/\w.-] - The pattern for matching a URL character.
- )+ - Repeat the group.
To force it to match the entire string, anchor the entire pattern with ^ at the start and $ at the end; otherwise it is free to only match a portion of the string. With this change, it becomes:
/^((?!\.html$)[/\w.-])+$/
References
regex/all_text_not_containing.txt · Last modified: 2025/05/27 07:55 by peter