How to write regular expression with alternative search ending phrase?

Alternative: Alternative Search Engines forum discussing any other search engine not listed above, including Asian and European search engines. Alternative engines include Baidu.com, Alibaba, Kosmix, Jadoo, and more.

Moderator: derek88

How to write regular expression with alternative search ending phrase?

Postby Sami » Thu Jul 23, 2009 4:25 am

I need expression that would match:
concrete word
eventually some word or other one
something - what I want to capture
ending being few alternative phrases, where match is stopped at first one matching found
I meant:
word(.*)(^something|other thing)

and in string:
word captured text something other thing

it doesn't stop on something but goes till other thing :/
What I tried:

(?:word)(?:word){0,1}(.*)\b(?>ending|other ending)\b
Sami
 
Posts: 1
Joined: Thu Jul 23, 2009 4:25 am

How to write regular expression with alternative search ending phrase?

Postby Tom M » Thu Jul 23, 2009 4:30 am

Your explanation is a bit fuzzy, but i think you're looking for this:

foo.*bar(something)(a|b|c)

foo is your concrete word
.* is anything
bar is the other word
something should be your expression for what you want to capture
(a|b|c) is the alternates
Tom M
 
Posts: 1
Joined: Thu Jul 23, 2009 4:30 am

How to write regular expression with alternative search ending phrase?

Postby kindom_2006 » Thu Jul 23, 2009 4:43 am

Ok, this is really not enough info to answer the question fully, but ...

let's assume your word is "apple"

to match "apple" you need /apple/
simple.

let assume you have a second word, "orange"

then /(apple|orange)/

Note that with regex syntax, maybe slightly different depending on what language you're using

Ok, now regards capture this fully depends on what language you're using. It's pretty much completely different in every programming language. But often the captured expression string is referred to by \1 or $1

anyway ... continuing on alternate endings:

Lets say you want to find the endings: "green" "sweet" or "seeds".

Then perhaps you could use:

/((apple|orange) (green|sweet|seeds))/

by using separate parenthesis sets, \1 or $1 will be the entire phrase, \2 or $2 will be apple or orange, and \3 or $3 will hold the final part, green, sweet or seeds.

If you want to captures "anything" between your start and your end, then maybe :

/((apple|orange)(.*)(green|sweet|seeds))/

will be what you want, in this case matches 1 and 2 are like the above, and 3 is your "anything" 4 is the terminus, green/sweet/seeds.

I think that's all I can answer,

hth
kindom_2006
 
Posts: 1
Joined: Thu Jul 23, 2009 4:43 am


Return to Search Engines - Alternative

Who is online

Users browsing this forum: No registered users and 1 guest

cron