5

I am trying to select all rows from a table where column contains an element from a list: Something like

Select * from `table` where `column` (contains anything from {£,$,%,^,&,...,/})

This is basically an illegal character check.

Can anyone help?

Thanks

4 Answers 4

10

For MySQL you may use REGEXP or RLIKE to check specific column for pattern matching. In your case following example might work:

SELECT * FROM `table` WHERE `column` REGEXP '[\£\$\%\^\&]';
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for this, do you know of an escape sequence for *? I want this as an illegal character too, struggling to find anything on it
Escape everything with backslash. Result: [\£\$\%\^\&\*\?].
0

You can use LIKE for pattern matching,

SELECT  *
FROM    `table`
WHERE   `column` LIKE '%£%' OR
        `column` LIKE '%$%' OR
        `column` LIKE '%\%%' OR
        `column` LIKE '%&%'

Comments

0

If I understood this correctly you want all rows which have non alphanumeric characters ie other than digits and alphabets

SELECT * FROM `table` WHERE `column` REGEXP '^[^a-zA-Z0-9]+$'

The ^ inside [ ] charcter class implies negation while outside at the beginning of regular expression specifies starting of column value. $ imples ending of string value

Comments

0
SELECT * FROM table WHERE column LIKE '%\%%' OR column LIKE '%$%' OR column LIKE '%&%';

...etc. '%char%' means that there is char somewhere, '%char' means that char is at the end of string, 'char%' means that it is at the beginning. '%\%%' means that searched char (%) is a special char used by mysql and '\' is necessary.

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.