I want to match any word that starts/ends or not contain with word "end" but ignore word "end", for example:
but
I'm using ^(?!end)).*$
but its not what I want.
Sorry for my english
To match any character except a list of excluded characters, put the excluded charaters between [^ and ] . The caret ^ must immediately follow the [ or else it stands for just itself. The character '.
Following example shows how to search duplicate words in a regular expression by using p. matcher() method and m. group() method of regex. Matcher class.
Similarly, the negation variant of the character class is defined as "[^ ]" (with ^ within the square braces), it matches a single character which is not in the specified or set of possible characters. For example the regular expression [^abc] matches a single character except a or, b or, c.
The metacharacter \b is an anchor like the caret and the dollar sign. It matches at a position that is called a “word boundary”. This match is zero-length.
Regex Match All Except a Specific Word, Character, or Pattern December 30, 2020 by Benjamin Regex is great for finding specific patterns, but can also be useful to match everything except an unwanted pattern. A regular expression that matches everything except a specific pattern or word makes use of a negative lookahead.
This expression will ignore any string containing an a: /^(?!.*a).*/ If the character you want to exclude is a reserved character in regex (such as ? or *) you need to include a backslash \ in front of the character to escape it, as shown:
For example, here’s an expression that will match any input that does not contain the text “ignoreThis”. /^(?!.*ignoreThis).*/ Note that you can replace the text ignoreThis above with just about any regular expression, including:
) Closing tag for negative lookahead. [\w]+ character class to capture words. Explanation: The regex search will only look for locations starting with word boundaries, and will remove matches with end as only word. i.e [WORD BOUNDARY]end [END OF WORD BOUNDARY]. \w will capture rest of the word.
Try this:
^(?!(end)$).+$
This will match everything except end.
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