Jump to content

pattern matching


lxndr

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.


Link to comment
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)


Link to comment
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 !

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.