MySQL Regex matching newline or end of string

full-text-searchMySQLregular expression

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.

Best Answer

Found the solution myself:

SELECT * FROM table WHERE column REGEXP 'myValue(\r\n.*)?$'