[thelist] regex help
Frank
lists at frankmarion.com
Tue Sep 2 20:46:44 CDT 2003
At 06:11 PM 2003-09-02 -0700, you wrote:
So if I understand you correctly, you will always need to remove the third
set of "s#" regardless? Piece o'cake.
mystring = 's111s222s333s444s555'
regex = (s[0-9]+){2}(s[0-9]+){1}
(Find 's' followed by any quantity of numbers.){twice}
(s[0-9]+){2} = 's111s222'
(Find 's' followed by any quantity of numbers.){once}
(s[0-9]+){1}
To access the first pattern (in parentheses means "remember this") use
\1
To access the first pattern (in parentheses means "remember this") use
\2
I don't know how this would be written in PHP (I think you are a PHP man,
yes?). Pattern number two identifies the third set of "s and numbers". It
is identified (called "backreferencing") as \2
Next use PHP to replace \2 from $mystring with '' (nothing) and you will
be left with
mystring = 's111s222s444s555' <-(s333 is gone)
This is probably not the best way, but it's mighty expedient, and probably
fast.
Hope this helps.
--
Frank Marion lists at frankmarion.com Keep the signal high.
More information about the thelist
mailing list