• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • 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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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