0

I need a regex which helps me searching through the database.

It should be able to do:

  1. In word searching. Example: ell => Hello, Yello, Mellt, ....
  2. Similar words: Example: gold => hold, golt, cost, ...

Is this possible to do with a regex?

If yes how does this regex look like?

Regards

bodokaiser
  • 15,122
  • 22
  • 97
  • 140
  • 1
    What kind of database? What kind of language that allow you to search through the database? – nhahtdh Jul 23 '12 at 10:31
  • Is this relevant? Here is the original thread. See the bottom. I just have to place a regex. http://stackoverflow.com/questions/11609697/expressjs-search-query-api As I know mongoosejs doesn't have a full-text-search, search option – bodokaiser Jul 23 '12 at 10:32
  • It is relevant, since regex is not the same in all languages/tools. If we know the technology you are using, we might suggest something else better that can solve your problem. – nhahtdh Jul 23 '12 at 10:36

2 Answers2

1
  1. Would usually be done via the LIKE operator with wildcards:

    WHERE column LIKE '%ell%'
    
  2. Can be done with a string similarity measure, such as Levenshtein distance. Here is an implementation for MySQL as a Stored Procedure. However, for nearly every string similarity algorithm "gold" and "cost" are quite far apart.

Joey
  • 344,408
  • 85
  • 689
  • 683
0

This is very general question. I can only recommend simple solution:

Lets have the first example you stated:

$your_root = "el"

then:

$string =~ /\w*$your_root\w*/

matches 'h el lo', 'y el lo' but also 'iafbi342b el erger64'

René Kolařík
  • 1,244
  • 1
  • 10
  • 18