I'm wanting to use a Regular Expression in SQLs 'LIKE' function to be able to search for strings containing a particular word.
For example, let's say I have a list of folder names (from a laptop) and I want to search for all of the folders that contain the word "Old". Example of results I want:
Folder Name |
---|
Old Templates |
old Archives |
temp - old |
However, when I use:
WHERE folder LIKE '%Old%'
Obviously, I get the following results:
Folder Name |
---|
Old Templates |
old Archives |
temp - old |
Harold Jenkins |
Jerry Oldfield |
I just want to use a Regular Expression which searches for the word "Old" at any stage of the string but it searches for only the 3 characters and retrieves the full string.
Just wondering if anyone can help me out - thanks!
CodePudding user response:
Generally, the like
operator has limited functionality, certainly less than regexp. However, what you need can be done by
- Appending a space to the beginning and end of your search string to ensure it's a different word
- Doing the same to the target string, so that it will also be matched in the edges:
where ' ' folder ' ' like '% old %'