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
https://forums.phpfreaks.com/topic/247349-return-and-replace-data/
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

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.