• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • Last Modified:

regular expressions for simple data search

i am trying to figure out how to write some proper regular expressions for one of my forms that can search selected data and fill in its listview.  even with 'expresso' regular expression program.  no luck so far...

data examples:

green_apple
evergreen
yellow_apple
green_yellow_apple
apple_green
green_apple_yellow
blue_seed
etc...

input examples: (before i press 'search' button)

green*               (green + anything)
*green               (anything + green)
^apple                (begins with 'apple' only)
apple$                (ends with 'apple' only)
a??le                   (any characters within a single '?')
?ell?w                 (ditto)
apple AND green  (self explanation) i might remove 'AND' and use white space only?
apple OR green    (ditto)
seed                   (all data with 'seed')

these symbols will be replaced with simple RE by cs coding, for example:
* -> [a-z]+
? -> [a-z]
^ -> ^(?=string).*
$ -> .*string.$
none -> .*string.*
two words with AND -> (?=.*string)(?=.*string)
etc...

but if i put some tricky combinations, for example; ^g*n AND a??le$
i became stuck...  any suggestions on flexible RE and CS coding?
thanks
0
rizel
Asked:
rizel
  • 4
  • 2
1 Solution
 
gregoryyoungCommented:
I am just curious here ... would not green* and ^green be the exact same thing ?


0
 
rizelAuthor Commented:
checked them in 'expresso' and i didn't realize they are  lol :)
hmm...
if i input 'blue and green*' and i would expect the program to find any data with blue and green???? that way.
ex. in the data: blue apple and greenhouse
but if i input '^green green*' it won't make any sense since you mentioned it :)
0
 
gregoryyoungCommented:
your wild card should just be a * ...

the more fun thing is when you have a * in your data :)
*gre*en*
*green*
*green
green*
more fun is ...

*green** //is this ?????????green*?????? or ??????????green?????????

how do you escape your control characters?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rizelAuthor Commented:
escape?  you mean, using backslash and a character such as \s, etc?

i did some silly expressions such as above and RE did the dirty work and gave me some silly results ;)

hmm..i wonder if you are suggesting i should use a * instead of those symbols i wrote here?
0
 
rizelAuthor Commented:
argh...  i realized that i already solved my problem AND overlooked it,
then as long as i continued, the problem became worse :p
fixed it and it is alright...

thanks
0
 
rizelAuthor Commented:
reason:

if(split[a].IndexOf("*") > -1) split[a] = split[a].replace("*", ".*"); // it was correct at the first place

if(split[a].IndexOf("*") > -1) split[a] = split[a].replace("*", "[a-z]"); // i replaced it carelessly
i think this one was supposed to be for '?' not '*'
0
 
Bob LearnedCommented:
My question:  Why don't I see any Regular Expressions here?

Bob
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now