Connecting Tech Pros Worldwide Help | Site Map

regex question.

  #1  
Old July 17th, 2005, 10:59 AM
chris
Guest
 
Posts: n/a
just learning regex is it posible ?

say i have a string " this is a really funny string"

and want to leave the middle untouched but replace the outer parts

EG ens up with "that was a really funny rope"

so for example find a string with "this is" on the begining and replace it
with "that was"
and with "string" on the end and replace it with "rope"
BUT whatever is inbeteween remains untouched

is this possible ??

chris


  #2  
Old July 17th, 2005, 10:59 AM
d
Guest
 
Posts: n/a

re: regex question.


It's very possible :)

You can use things called "anchors" to specify that your pattern has to
match either the beginning or the end of a string. The character ^ means
start, and $ means end.

preg_replace("/^this is/", "that was", $string);

says "replace 'this is' at start of $string with 'that was'" :)

d.

"chris" <someone@here.com> wrote in message
news:41bd670d$1@funnel.arach.net.au...[color=blue]
> just learning regex is it posible ?
>
> say i have a string " this is a really funny string"
>
> and want to leave the middle untouched but replace the outer parts
>
> EG ens up with "that was a really funny rope"
>
> so for example find a string with "this is" on the begining and replace it
> with "that was"
> and with "string" on the end and replace it with "rope"
> BUT whatever is inbeteween remains untouched
>
> is this possible ??
>
> chris
>[/color]


  #3  
Old July 17th, 2005, 10:59 AM
Pedro Graca
Guest
 
Posts: n/a

re: regex question.


["Followup-To:" header set to comp.lang.php.]
chris wrote:[color=blue]
> just learning regex is it posible ?[/color]

Try the "regex-coach"
http://www.weitz.de/regex-coach/

Example (picture will be deleted in 30 days)
http://www.pixpond.com/xx/regex.png

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
  #4  
Old July 17th, 2005, 10:59 AM
peter
Guest
 
Posts: n/a

re: regex question.


explode(" ",$string); would copy all the words into an indexed array

chris wrote:[color=blue]
> just learning regex is it posible ?
>
> say i have a string " this is a really funny string"
>
> and want to leave the middle untouched but replace the outer parts
>
> EG ens up with "that was a really funny rope"
>
> so for example find a string with "this is" on the begining and replace it
> with "that was"
> and with "string" on the end and replace it with "rope"
> BUT whatever is inbeteween remains untouched
>
> is this possible ??
>
> chris
>
>[/color]
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Python regex question Tim N. van der Leeuw answers 0 August 15th, 2008 12:55 PM
Regex question pedrito answers 4 August 31st, 2007 06:05 PM
Regex question pedrito answers 1 August 30th, 2007 02:55 PM
Regex Question JM answers 1 July 2nd, 2006 06:55 AM
Regex Question JM answers 1 July 1st, 2006 09:05 AM