Jump to content

Archived

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

lxndr

pattern matching

Recommended Posts

Can anyone tell me how I could pattern match the following from a string and extract the matched text as a new string?

begins with '( '
then has a number of alphanumeric characters
ends with 'sion)'

Thanks in advance.


Share this post


Link to post
Share on other sites
[code]<?php

$str = '( confusion)';

preg_match('/\( ([A-Za-z0-9]*)sion\)/', $str, $m);
$match = $m[1];

echo $match;

?>[/code]

Will echo "confu"

Share this post


Link to post
Share on other sites
[!--quoteo(post=379364:date=Jun 2 2006, 04:18 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 2 2006, 04:18 PM) [snapback]379364[/snapback][/div][div class=\'quotemain\'][!--quotec--]
[code]<?php

$str = '( confusion)';

preg_match('/\( ([A-Za-z0-9]*)sion\)/', $str, $m);
$match = $m[1];

echo $match;

?>[/code]

Will echo "confu"
[/quote]

Hi,

Thanks for your message. I didn't quite explain myself correctly... what I want to be able to do is extract everything within the brackets .. e.g:

Blah blah blah (1943 version) ->> (1943 version)

Some more blah (original version) ->> (original version)


Share this post


Link to post
Share on other sites
Oh, OK:

[code]<?php

$str = 'Blah blah blah (1943 version)';

preg_match('/\(([A-Za-z0-9]*) version\)/', $str, $m);
$match = $m[0];

echo $match;

?>[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=379383:date=Jun 2 2006, 05:12 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 2 2006, 05:12 PM) [snapback]379383[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Oh, OK:

[code]<?php

$str = 'Blah blah blah (1943 version)';

preg_match('/\(([A-Za-z0-9]*) version\)/', $str, $m);
$match = $m[0];

echo $match;

?>[/code]
[/quote]

Thanks for your help. Much appreciated !

Share this post


Link to post
Share on other sites

×

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.