I've example text:
$text = "I've got a many web APP=. My app= is not working fast. It'= slow app=";
It is necessary to replace the symbol "=" with the letter "s" by the following condition: If the right or left with the "=" sign has a letter then replace it with the letter "s". Teaching the register of letters in the parent word. It would be better if you create three kinds of functions. One teaches the parent register, the second does not teach the register and replaces the upper letter "S" and the third with the small letter "s". As a result, there will be three results:
I've got a many web APPS. My apps is not working fast. It's slow apps - case insensitive regex replacing variant
I've got a many web APPS. My appS is not working fast. It'S slow appS - uppercase regex replacing variant
I've got a many web APPs. My apps is not working fast. It's slow apps lowercase regex replacing variant
My long code here:
$search = array("a=", "b=", "c=", "d=", "e=", "f=", "g=", "h=", "i=","j=", "k=", "l=", "m=", "o=", "p=","r=", .... , "z=");
$replace s array("as", "bs", "cs", "ds", "es", "fs", "gs", "hs", "is","js", "ks", "ls", "ms", "os", "ps","rs", .... , "zs");
$result = str_ireplace($search, $replace, $text);
You may try this:
=(?=[\w'-])|(?<=[\w'-])=
and replace by this:
"s" or "S" to get your desired result.
However this will meet condition 2 and 3 for your output.
For Condition 1 you need more than one operation (if you are stick to regex only solution):
Operation 1:
Search By this:
=(?=[A-Z])|(?<=[A-Z])=
replace by this:
"S"
Operation 2:
Search the resultant of operation 1 with this:
=(?=[a-z0-9_'-])|(?<=[a-z0-9_'-])=
and replace by this:
"s"
Sample Source: ( run here )
<?php
$re11='/=(?=[A-Z])|(?<=[A-Z])=/';
$re12= '/=(?=[a-z0-9_\'-])|(?<=[a-z0-9_\'-])=/';
$re = '/=(?=[\w\'-])|(?<=[\w\'-])=/';
$str = 'I\'ve got a many web APP=. My app= is not working fast. It\'= slow app=';
echo "\n #### condition 1: all contexual upper or lowercase s \n";
$subst = 'S';
$result = preg_replace($re11,'S', $str);
$result = preg_replace($re12,'s', $result);
echo $result;
echo "\n ##### condition 2: all small case s \n";
$subst = 's';
$result = preg_replace($re, $subst, $str);
echo $result;
echo "\n ##### condition 3: all upper case S \n";
$subst = 'S';
$result = preg_replace($re, $subst, $str);
echo $result;
?>
Sample Output:
#### condition 1: all contexual upper or lowercase s
I've got a many web APPS. My apps is not working fast. It's slow apps
##### condition 2: all small case s
I've got a many web APPs. My apps is not working fast. It's slow apps
##### condition 3: all upper case S
I've got a many web APPS. My appS is not working fast. It'S slow appS