I'm looking for a regular expression that removes illegal characters. But I don't know what the characters will be.
For example:
In a process, I want my string to match ([a-zA-Z0-9/-]*)
. So I would like to replace all characters that don't match the regexp above.
They use a regular expression pattern to define all or part of the text that is to replace matched text in the input string. The replacement pattern can consist of one or more substitutions along with literal characters. Replacement patterns are provided to overloads of the Regex.
The REPLACE command requires one of the two possible actions take place: If no matching value is found with the existing data row, then a standard INSERT statement is performed. If the duplicate record found, the replace command will delete the existing row and then adds the new record in the table.
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).
indexOf() that takes a regular expression instead of a string for the first first parameter while still allowing a second parameter ? str. lastIndexOf(/[abc]/ , i); While String.search() takes a regexp as a parameter it does not allow me to specify a second argument!
That would be:
[^a-zA-Z0-9/-]+
[^ ]
at the start of a character class negates it - it matches characters not in the class.
See also: Character Classes
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