lcj

The [Frog | Kangaroo] jumps over the [pond | river] to catch a lizard, eat a fly, step on a worm.

How do I pull out of this string which one was chosen, the frog or the kangaroo.

What's between the frog or kangaroo and the pond or river.

And a list of the things:

catch a lizard,

eat a fly,

step on a worm.

Using groups. In three expressions



Re: Regular Expressions Between two words

Adamus Turner

(frog|kangaroo) jumps over the (pond|river) to (catch a lizard|eat a fly|step on a worm)

Adamus






Re: Regular Expressions Between two words

lcj

Now how do I put them into groups The options (frog or kangaroo) as well as the stuff between (jumps over the).



Re: Regular Expressions Between two words

tonn

Hi Icj,
When you say 'groups' do you mean 'capturing groups'
If so: capturing groups are denoted by parentheses. By putting something between parentheses like ( ... ) the match, if found, is automatically placed into a capturing group. The first group gets index 1, the next one gets index 2 etc.