List Info

Thread: Making the regex engine "halt" after each match




Making the regex engine "halt" after each match
user name
2006-02-18 07:50:42
Hello!

I'd like to do the following:

Given just one line of text, match every occurrence of a
double letter
and push those double letters on my_stack. Say, if we are
given

$line = "This line contains some occurrences of double
letters,
hoorray";

then I want my_stack to end up containing "cc",
"rr", "tt", "oo",
"rr";

Everything I tried so far just put the first occurrence of
double
letters (in this example, "cc") on the stack,
even if I used the /g
option for my match. I suppose the regex engine matched
every
occurrence, but somehow it didnt "halt" and
"care to push" every single
one of the on my_stack.

So... how should I go about the above problem?

Many thanks for your help!! Dominic


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

Making the regex engine "halt" after each match
user name
2006-02-18 20:19:22
contrary to what u r probably  thinking, regex engine of any
flavor
does keep track of the matches it's gathering. They are
collected as a
Match collection (string array). For example using your
input

This line contains some occurrences of double letters,
hoorray

and match pattern

([a-z])\1

we can catch 6 occurrences of double letters:

Match $1
cc
rr
tt
oo
rr

then u can accees the Match Collection and assign the 6
values to your
variable(s)
or do some smth else with them.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )