If the only prohibited character is the equals sign, something like [^=]* should work.

[^...] is a negated character class; it matches a single character which is any character except one from the list between the square brackets. * repeats the expression zero or more times.

Answer from tripleee on Stack Overflow
🌐
QBasic on Your Computer
chortle.ccsu.edu › finiteautomata › Section07 › sect07_12.html
Basic Regular Expressions: Exclusions
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 '.' (period) is a metacharacter (it sometimes has a special meaning).
🌐
RegexOne
regexone.com › lesson › excluding_characters
RegexOne - Learn Regular Expressions - Lesson 4: Excluding specific characters
To represent this, we use a similar expression that excludes specific characters using the square brackets and the ^ (hat). For example, the pattern [^abc] will match any single character except for the letters a, b, or c.
Discussions

Regex match anything but
The trick is to do the negative assertion at every point in the expression, and you need to anchor both the start and the end, something like /^(?:(?!red|green|blue).)*$/ should do the trick as shown here: https://regex101.com/r/lfeLIi/1 More on reddit.com
🌐 r/regex
7
4
June 30, 2022
Regexp to match everything "except these"
I am wanting to sanitize a user ... and the sanitized string should only be allowed to have plus or minus characters in it. I thought this would be a rather simple thing to do with regex, but I'm struggling to find some thing that will catch all the special characters (except for - and ... More on sololearn.com
🌐 sololearn.com
9
0
regular expression - Match any character except a specific one at the start of a string, or any whitespace - Unix & Linux Stack Exchange
8 sed: Portable solution to match "any character but newline" 2 How can I match all characters up to the second to last white space character in a string? 15 Replace every occurence of a character except the last one in every line · 1 regex match specfic string without specfic trailing character More on unix.stackexchange.com
🌐 unix.stackexchange.com
June 11, 2024
regex - Match any character except ' - Stack Overflow
I want to match any character (case insensitive) except when preceded by a single quote followed by the text On Error Goto: Match: on error goto err_handler if aap = 0 then on error goto Myerrorhan... More on stackoverflow.com
🌐 stackoverflow.com
🌐
NTU Singapore
www3.ntu.edu.sg › home › ehchua › programming › howto › Regexe.html
Regular Expression (Regex) Tutorial
[.-]? matches an optional character . or -. Although dot (.) has special meaning in regex, in a character class (square brackets) any characters except ^, -, ] or \ is a literal, and do not require escape sequence.
🌐
Reddit
reddit.com › r/regex › regex match anything but
r/regex on Reddit: Regex match anything but
June 30, 2022 -

Hello all.

Can anyone help me with the below request?

I need a regex condition that matches anything EXCEPT the specified strings. I have tried the following regex, but unfortunately it does not match if I have a string that contains one of the values listed below, e.g. "blue dragon" does not match because it contains "blue". I need it to match if it isn't exactly the values I have in the regex, so if I have "blue dragon" it matches still, although I have "blue" in the regex.

Thanks in advance!

^(?!.*(red|green|blue))
🌐
O'Reilly
oreilly.com › library › view › regular-expressions-cookbook › 9781449327453 › ch05s04.html
5.4. Find All Except a Specific Word - Regular Expressions Cookbook, 2nd Edition [Book]
August 27, 2012 - You want to use a regular expression to match any complete word except cat. Catwoman, vindicate, and other words that merely contain the letters “cat” should be matched—just not cat. A negative lookahead can help you rule out specific words, and is key to this next regex: ... Although a negated character class (written as ‹[^⋯]›) makes it easy to match anything except a specific character, you can’t just write ‹[^cat]› to match anything except the word cat.
Authors: Jan GoyvaertsSteven Levithan
Published: 2012
Pages: 609
Find elsewhere
Top answer
1 of 2
3

Use

^[^'\n\r]*On Error Goto

Use i case insensitive mode and m multiline mode. See proof.

Explanation

--------------------------------------------------------------------------------
  ^                        the beginning of the string
--------------------------------------------------------------------------------
  [^'\n\r]*                any character except: ''', '\n' (newline),
                           '\r' (carriage return) (0 or more times
                           (matching the most amount possible))
--------------------------------------------------------------------------------
  On Error Goto            'On Error Goto'
2 of 2
2

Updated link to regex test cases: https://regex101.com/r/UYll0h/6

Since there can be no character when ' isn't there, therefore you will need to use a look-ahead assertion.

Since there can also be other characters of the code (other than ') in the line before on error goto (like in the line if aap = 0 then on error goto Myerrorhandler), to handle those, you will also need to put a condition to check if any character other than ' is present after the look-ahead. This will be done by ([^']+)?.

^(?!')([^']+)?on error goto

The (?) is called a look-ahead. It checks if the characters inside it are present or not. Unlike [], (?) will assert true even when there are no characters. So for example, [a] will check if the first character is 'a', but any expression after it will check from the second character. On the other hand, (?=a) will check if the first character is 'a', and any expression after it will check from the first character. In other words, the look-ahead doesn't move the regex engine to the next character if a match is not found.

🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › standard › base-types › character-classes-in-regular-expressions
Character Classes in .NET Regular Expressions - .NET | Microsoft Learn
September 8, 2025 - Any character. The . (dot or period) character in a regular expression is a wildcard character that matches any character except \n.
🌐
Quora
quora.com › What-is-a-regular-expression-that-can-match-anything-except-if-it-contains-a-certain-string
What is a regular expression that can match anything, except if it contains a certain string? - Quora
Answer (1 of 4): For any given string w, it is possible to define a regular expression that matches any string not containing w, and no string that contains w. It is the complement of the regular expression £*w£*, where £ is the alphabet (usually written as a Sigma, but I don't have that ...
🌐
Medium
medium.com › @qdangdo › regex-a-way-to-match-any-pattern-of-string-1dd327130fc6
Regex: A Way to Match Any Pattern of String | by Quang Do | Medium
October 5, 2021 - . - Any Character Except New Line \d - Digit (0-9) \D - Not a Digit (0-9) \w - Word Character (a-z, A-Z, 0-9, _) \W - Not a Word Character \s - Whitespace (space, tab, newline) \S - Not Whitespace (space, tab, newline)
🌐
Python documentation
docs.python.org › 3 › library › re.html
re — Regular expression operations — Python 3.14.7 ...
If the first character of the set is '^', all the characters that are not in the set will be matched. For example, [^5] will match any character except '5', and [^^] will match any character except '^'. ^ has no special meaning if it’s not ...
🌐
Medium
suragch.medium.com › how-to-match-any-single-character-with-a-regular-expression-421b9fc13681
How to match any single character with a regular expression | by Suragch | Medium
January 11, 2019 - Example 2 regex: a[0-7]c · a0c // match a3c // match a7c // match a8c // no match ac // no match a55c // no match · Use the hat in square brackets [^] to match any single character except for any of the characters that come after the hat ^. 6.3K ...
🌐
Reddit
reddit.com › r/regex › how to match any character, except one specific character?
r/regex on Reddit: How to match any character, except one specific character?
October 17, 2022 -

I need to replace a server name in a file and the file is in somewhat of a key-value format:

"serverState":"online","server_name":"serverName","ssh_enabled":true

I need to replace serverName with the new name. The problem is, serverName can contain numbers, letters, and special characters (such as "-").

This one works for numbers and letters:

(?:server_name":")(\w|\d)*(?:")

But what if the server name is server-name?

If I try to match any character, it'll include everything past the end quotation, including "ssh_enabled":true, etc:

(?:server_name":").*(?:")

I've tried using a negative look ahead to match any character except ":

(?:server_name":")(?!")*(?:")

But this doesn't match anything.

So how can I match only what's between the quotations for the server_name value, to include letters, numbers, and special characters?

Edit:

Solved:

(?:server_name":")[^"]*(?:")
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › regex › char_classes.html
Character Classes (The Java™ Tutorials > Essential Java Classes > Regular Expressions)
Enter your regex: [bcr]at Enter ... defined by the character class. To match all characters except those listed, insert the "^" metacharacter at the beginning of the character class....
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Regular_expressions › Cheatsheet
Regular expression syntax cheat sheet - JavaScript | MDN
2 weeks ago - This page provides an overall cheat ... in the RegExp guide. If you need more information on a specific topic, please follow the link on the corresponding heading to access the full article or head to the guide. Character classes distinguish kinds of characters such as, for example, distinguishing between letters and digits. Assertions include boundaries, which indicate the beginnings and endings of lines and words, and other patterns indicating in some way that a match is possible ...