regex question.

This is a discussion on regex question. within the PHP Language forums, part of the PHP Programming Forums category; explode(" ",$string); would copy all the words into an indexed array chris wrote: > just learning regex is ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-12-2004
peter
 
Posts: n/a
Default Re: regex question.

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

chris wrote:
> 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
>
>

Reply With Quote
  #2 (permalink)  
Old 12-13-2004
chris
 
Posts: n/a
Default regex question.

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


Reply With Quote
  #3 (permalink)  
Old 12-13-2004
d
 
Posts: n/a
Default 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...
> 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
>



Reply With Quote
  #4 (permalink)  
Old 12-13-2004
Pedro Graca
 
Posts: n/a
Default Re: regex question.

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


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!
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:29 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0