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. 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" 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) 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] 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 ! Link to comment https://forums.phpfreaks.com/topic/11026-pattern-matching/#findComment-41223 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.