lxndr Posted June 2, 2006 Share Posted June 2, 2006 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 charactersends with 'sion)'Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/11026-pattern-matching/ Share on other sites More sharing options...
poirot Posted June 2, 2006 Share Posted June 2, 2006 [code]<?php$str = '( confusion)';preg_match('/\( ([A-Za-z0-9]*)sion\)/', $str, $m);$match = $m[1];echo $match;?>[/code]Will echo "confu" Quote Link to comment https://forums.phpfreaks.com/topic/11026-pattern-matching/#findComment-41201 Share on other sites More sharing options...
lxndr Posted June 2, 2006 Author Share Posted June 2, 2006 [!--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) Quote Link to comment https://forums.phpfreaks.com/topic/11026-pattern-matching/#findComment-41215 Share on other sites More sharing options...
poirot Posted June 2, 2006 Share Posted June 2, 2006 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 Link to comment https://forums.phpfreaks.com/topic/11026-pattern-matching/#findComment-41220 Share on other sites More sharing options...
lxndr Posted June 2, 2006 Author Share Posted June 2, 2006 [!--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 ! Quote Link to comment https://forums.phpfreaks.com/topic/11026-pattern-matching/#findComment-41223 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.