I have this string: 'mr (3_22) mrs (1_12) miss (2_4)'
I want php to output that string to: (3_22)(1_12)(2_4)
How can i do that with php?
Find multiple matches with regex in php string
-
- Posts: 107
Find multiple matches with regex in php string
Admin
You can use preg_match_all(). Try the following code:
Code: Select all
$str ='mr (3_22) mrs (1_12) miss (2_4)';
$re ='';
if(preg_match_all('/(\([^\)]+\))/i', $str, $mt)){
$re = implode('', $mt[0]);
}
echo $re; // (3_22)(1_12)(2_4)
Similar Topics
-
Move the string that matches the regex to the end
JavaScript - jQuery - Ajax
First post
I have the following problem to solve it in JavaScript:Last post
- Find the text which is between small brackets and shift that text with the brackets to...
Try the following code:
function testToEnd(str){
//get matched string
let st = str.match(/ *\( +\) */g)
if(st){
st = st ;
// replace the... -
Make regex replace() work on all matches
JavaScript - jQuery - Ajax
First post
I’m trying to replace all spaces within a string with hyphens.Last post
I tried this:
let str ='This is my text';
str = str.replace(/\s/, '-');...
Add the global search flag (/g ) to your regex to match all occurrences.
let str ='This is my text';
str = str.replace(/\s/g, '-');... -
Find item in array and set as first index
JavaScript - jQuery - Ajax
First post
Say I have the following array of persons:Last post
const arr =
And I want to find a certain person (name) in this array, and put it as the first...
You could sort the array with the sort() method.
This approach moves all objects with the wanted 'name' to top.
const arr = ;
let first =... -
Adding string from database into PDF
PHP - MySQL
First post
Hello Coursesweb I have a problem with my php document to convert it to PFDLast post
I cant find out how to get results from $users into the HTML to the PDF...
Thanks MarPlo I prefer not to ask anything on stackoverflow.com
because I once typed a small i instead of I.
and received many comments about it.... -
Remove backslash from string
PHP - MySQL
First post
How can I remove backslashes from string in php?Last post
I tried the following code.
$str ='abc-\123';
$str = stripcslashes($str);
echo $str; //...
You can use str_ireplace() to remove backslash from string in php, but like in the following code (add two backslashes into the removing argument):...