I have the following regex that checks for a list of valid characters:
^([a-zA-Z0-9+?/:().,' -]){1,35}$
What I now need to do now is search for any existing columns in our DB that invalidates the above regex. I'm using the oracle SQL REGEXP_LIKE
command.
The problem I have is I can't seem to negate the above expression and return a value when it finds a character not in the expression eg
"a-valid-filename.xml"
=> this shouldn't be returned as it's valid.
"an_invalid-filename.xml"
=> I need to find these ie anything with an invalid character.
The obvious answer to me is to define a list of invalid characters... but that could be a long list.
You can match it against the following regex which uses the [^...]
negation character class:
([^a-zA-Z0-9+?/:().,' -])
This will match any single character that is not part of the list of characters that are allowed.
You can negate a character class by inserting a caret as the first character.
Example:
[^y]
The above will match anything that is not y
Try this:
where not regexp_like(col, '^([a-zA-Z0-9+?/:().,'' -]){1,35}$')
or
where regexp_like(col, '[^a-zA-Z0-9+?/:().,'' -]')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.