Jump to content

return and replace data


bandito

Recommended Posts

Hey guys,

 

I am trying to return some data between 2 delimiters.  For example I have sdfkasdjfk address: 1 smith road: asdkfasdjf and I want to be able to return address: 1 smith road: and replace it with an empty string.  The information between the address: and : is always different.  I have played around with preg_split(), preg_grep(), preg_replace but have had no luck.  Any ideas?

 

Thanks

Link to comment
Share on other sites

Nevermind, reread and I think I figured it out

 

/address: ([^:])/

 

$expr = '/address: ([^:]++)/';
$str = 'sdfkasdjfk address: 1 smith road: asdkfasdjf';

preg_match( $expr, $str, $match );

print_r( $match );

 

use preg_match_all() if you have multiple results you want to return

Link to comment
Share on other sites

Thanks xyph!  I ended up using booth and they work much better than what I had.  One question, in the regular expression for the work "address" , what would i need to do to see if there is 1 or more letter "d" or letter "s"?  Thanks again those regular expressions work great!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.