Boris Savc wrote:[color=blue]
> Have you got maybe some idea how to
> find "TEXT 9999" (9999 are random numeric fields) with "TEXT 99 TEXT 99"?[/color]
"Pedro Graca" <hexkid@hotpop. com> wrote in message
news:brpphu$653 t1$1@ID-203069.news.uni-berlin.de...[color=blue]
> Boris Savc wrote:[color=green]
> > Have you got maybe some idea how to
> > find "TEXT 9999" (9999 are random numeric fields) with "TEXT 99 TEXT[/color][/color]
99"?[color=blue]
>
> ????
>
> Try regexps:
> http://www.php.net/PCRE
>
> When you start using them you might find "The regex coach" [1] a very
> good tool.
>
> [1] http://www.weitz.de/regex-coach/
> --
> --= my mail box only accepts =--
> --= Content-Type: text/plain =--
> --= Size below 10001 bytes =--[/color]
I can find TEXT 9999 and change it to some TEXT but how about changing it to
TEXT1 99 and TEXT2 99, where 99 and 99 are the digits from original
expression. Any ideas?
You have really all the answers. Your tip for Regex Coach was great also.
I'm using it all the time. Hope I'll learn my regexps :-) But still one more
question: If I want to do the same with characters let's say XTEXTY change
with XTEXT TEXT TEXT Y how to do that? (\w finds it, but how to do a
replacement?)
Boris Savc wrote:[color=blue]
> But still one more
> question: If I want to do the same with characters let's say XTEXTY change
> with XTEXT TEXT TEXT Y how to do that? (\w finds it, but how to do a
> replacement?)[/color]
This one I'll let you figure out by yourself :-)
Parenthesis in the pattern _grab_ their contents into $1, $2, ...
and you can use these references in the substitution part
preg_replace('/
TEXT # match literal TEXT
(\d\d) # match two digits and grab into $1
(\d\d) # match two digits and grab into $2
/x', ## specify extended syntax for regexp
'TEXT $1 TEXT $2', # replace with TEXT (space)
# whatever was grabbed into $1
# (space) TEXT (space)
# and whatever was grabbed into $2
'TEXT8764');
Happy regexing :-)
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Comment