Try as I might, I can't get a RegEx to exclude space or single quotes.
I'd use PATINDEX if I was in SQL.
Or NOT a positive match on either space or single quote, if I could negate...
I've tried (for single quote only)
\w*[^']\w*
^\w*[^']\w*$
Please put me out of my misery so I can sleep tonight.
Edit:
To replace or remove characters that don't match a regex, call the replace() method on the string passing it a regular expression that uses the caret ^ symbol, e.g. /[^a-z]+/ . The replace method will return new string where the not matching characters are replaced or removed. Copied!
Example: The regex "aa\n" tries to match two consecutive "a"s at the end of a line, inclusive the newline character itself. Example: "a\+" matches "a+" and not a series of one or "a"s. ^ the caret is the anchor for the start of the string, or the negation symbol.
In regular expressions, the period ( . , also called "dot") is the wildcard pattern which matches any single character. Combined with the asterisk operator . * it will match any number of any characters.
^[^\'\ ]*$?
Quite simple. Does not allow empty strings.
^[^' ]+$
i think this
^\w*$
should work as \w
does not include single quote or space.
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