Php preg_match_all for pattern matching

I've used the code below to find matches for [sometextXX] where XX is a numeric. What code do I need to find similar matches where XX is a string which varies, and return the whole string including the brackets and also separately return the XX string in the $matches array?  
<?php
$sourcestring="your source string";
preg_match_all('~\[sometext(\d+)\]~',$sourcestring,$matches);
?>

Open in new window

LVL 1
ncwAsked:
Who is Participating?
 
amit_gConnect With a Mentor Commented:
Using \w+ instead of \d+ should give you what you want.

preg_match_all('~\[sometext(\w+)\]~',$sourcestring,$matches);
0
 
ncwAuthor Commented:
Thanks very much.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.