Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expression

Status
Not open for further replies.

tsilihin

Programmer
Joined
Dec 9, 2002
Messages
3
Location
AU
Hi

I have a series of values in a record column as such:

01|02|03|

Now, I want to select a record that contains a specified value.

If I used a LIKE expression such as

Code:
SELECT * FROM table WHERE column LIKE "_01|%"

where the value I'm searching for is '01|', I would eventually be getting false positives from values like '101|','301|' etc.

So my question is - if I use MySQL's REGEXP feature to select the value, would it be possible to construct the expression as such:

Code:
SELECT * FROM table WHERE column REGEXP ".*(^|\|)01\|.*"

where the value I'm searching for is 01| and I want to find it either at the beginning of the string, or preceded by a '|' then any sequence of characters?

Would the '^' signifying the beginning of the string be valid in the 'or' condition?

Any help would be appreciated.
 
Try this regexp:
Code:
"^(01|.*\|01)|.*"
//Daniel
 
Thanks a lot - don't know why I didn't think of that one :-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top