forked from nruffilo/regexquest.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregex.php
More file actions
24 lines (24 loc) · 675 Bytes
/
regex.php
File metadata and controls
24 lines (24 loc) · 675 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
$pattern = $_GET['find'];
$replace = $_GET['replace'];
$string = $_GET['string'];
if ($replace == "") {
$final = explode("/",$pattern);
if (stripos($final[count($final)-1],"g") !== false) {
$pattern = str_replace(array("/ig","/g"),array("/i","/"),$pattern);
preg_match_all($pattern,$string, $matches);
//echo implode("",$matches[1]);
echo implode(" ",($matches[0]));
} else {
preg_match($pattern,$string, $matches);
//var_dump($matches);
echo $matches[0];
//echo implode("",$matches[1]);
//echo implode("",($matches[0]));
}
} else {
//echo "- $pattern - $replace - $string";
$result = preg_replace($pattern,$replace,$string);
echo $result;
}
?>