0

I'm trying to convert this regex:

^.*[^a-z1-9\-].*$

to a regex to be used in an oracle database query. What I want to do is to find all rows that contains at least one character in the column name different of a-z, 0-9 and -.

The query

select * from device where regexp_like(ctnmname, '^.*[^a-z1-9\\-].*$')

returns all rows in the table.

EDIT

The problem was the regex with the 0 and a escaped -. It works with the regex ^.*[^a-z0-9-].*$

0

3 Answers 3

2

The regex itself looks OK. You might want to make it case-sensitive and include the 0:

SELECT * FROM device WHERE REGEXP_LIKE(mycolumn, '^.*[^a-z0-9-].*$', 'c');
Sign up to request clarification or add additional context in comments.

Comments

1

As the dash is the last in the character class, you won't need to escape it:

where regexp_like(ctnmname, '^.*[^a-z1-9-].*$')

However

where regexp_instr(ctnmname, '[^a-z1-9-]') > 0

might be easier to read...

See also SQL fiddle

2 Comments

Thanks for the answer beny23, but still not working. Gives the same result.
Can you edit your question and add some of the values present in your ctnmname column?
0
where not regexp_like(ctnmname, '^(\w|-)*$')

fiddle

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.