MySQL LIKE/RegExp help needed

From: Simon (spambucket_at_myoddweb.com)
Date: 03/26/05


Date: Sat, 26 Mar 2005 15:48:23 -0000

Hi,

I have a table with a column that contains many names, like "Ant Simon
Lucy",

if I was looking for one name in the string of names I would do...
SELECT * from classroom where name LIKE '%ant%'.

But the select above will return rows with names like 'antoine' or
'anthony'.

So I guess I could have a select with spaces...
SELECT * from classroom where name LIKE '% ant %'.

But that also does not work if 'ant' is the first or last entry in the list,
(like in the example above).

So to solve my problem I would need something like...
SELECT *
FROM classroom
WHERE
       name LIKE "ant %" // first item in the list with more
OR name LIKE "% ant %" // neither the first nor last item in the list
OR name LIKE "% ant" // the last entry in the list
OR name = "ant" // the only entry in the list

But that does not look right, it does the job I guess but not in a very
elegant way.

Can someone give me a RegExp that would look for an exact name, (case
insensitive), in a string of names.
And how would I escape special characters in the string itself, (in weird
cases where the name I am looking for is something like "An^t"

Many thanks in advance,

Simon



Relevant Pages

  • MySQL LIKE/RegExp help needed
    ... I have a table with a column that contains many names, like "Ant Simon ... if I was looking for one name in the string of names I would do... ... SELECT * from classroom where name LIKE '% ant %'. ...
    (comp.lang.php)
  • Ant - handling user input command-line flags
    ... I'm using Ant instead of shell scripts. ... What I need is to set a property to either a literal string or an empty ... situation to setting it to an empty string. ... my pair of complementary filtered targets to map this onto the strings. ...
    (comp.lang.java.softwaretools)
  • Ant: How to escape property substitution?
    ... If a property foo is defined, ... is replaced by the value of foo inside an ant ... How can I pass the string literally, ... I need a way to *escape* the property substitution ...
    (comp.lang.java.softwaretools)
  • Re: "final" in "for"
    ... public static void main(String args) ... for (final String strang: strangs) ... for (int ant: ants) ... for (final int ant: ants) ...
    (comp.lang.java.programmer)