Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a text column in mysql which contains some values separated by a newline. I want now to query by these values and thought a regex should help me with that by doing something like:

SELECT * FROM table WHERE column REGEXP 'myValue';

That works so far except I also have that string also as part of a longer value like myValueLonger, then it would match both, so I need to add the newline as a separator. So I tried

SELECT * FROM table WHERE column REGEXP 'myValue[\n]';

But that returns zero results, it looks like multiline is somehow not supported in MySQL regex?

That is where I'm already hanging right now, at the end I would also need to add a way to allow newline or the total end of string, as I don't want to end empty newlines at the end and beginning of my text field.

Does anyone know how this can be accomplished in MySQL?

Edit: Found the problem with the multiline stuff, I had \r\n breaks, so that works:

SELECT * FROM table WHERE column REGEXP 'myValue\r\n';

But still struggling with the issue how to do that OR the end of string.

share|improve this question
up vote 1 down vote accepted

Found the solution myself:

SELECT * FROM table WHERE column REGEXP 'myValue(\r\n.*)?$'
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.