MySQL Forums
Forum List  »  Full-Text Search

Re: how to find particular string from text column
Posted by: Rick James
Date: June 01, 2010 09:02PM

"Mastering Regular Expressions" is a good book.

Here's a breakdown of '(^|[|])SEWER\s*:\s*Septic([|]|$)'
(|) -- either of the two things inside ('|' means 'OR').
^ -- start of string ("anchored" at beginning) -- I am assuming your text could be
"SEWER:Septic|GARAGES:2|MICROWAVE:Yes"
If, instead you are sure to have '|' at both ends, as
"|SEWER:Septic|GARAGES:2|MICROWAVE:Yes|"
then the regexp could be simplified to:
'[|]SEWER\s*:\s*Septic[|]'

$ -- anchor at end
[] -- any of the set of characters inside. In this case [|], I am avoiding the special meaning of '|' as 'OR'
SEWER and : and Septic -- exact matches on those strings
\s -- "white space", that is, space, tab, carriage return, etc.
* -- zero or more of what preceeds (contrast + meaning 1 or more, and ? meaning 0 or 1)
\s* -- zero or more spaces, tabs, etc. (probably zero in your case)

Possibly, this is all you need:
REGEXP '[|]SEWER:Septic[|]'
or
LIKE '%|SEWER:Septic|%'
The percents are there because LIKE is anchored by default, unlike REGEXP.
LIKE tends to be faster (in MySQL), but REGEXP is more powerful.
LIKE has only two special characters ( % _ ); REGEXP has lots.

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: how to find particular string from text column
4734
June 01, 2010 09:02PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.