Reputation: 1204
Here my string ($commit$ + $Bug$)/$HR$*($Leader$^$IT$)
... I want to replace all $variable$
replace with 1...
like (1 + 1)/1*(1^1)
...
is there possible to replace with value 1 ??? how??
Don't care which variable in between $__$...
Please Help me...
Upvotes: 0
Views: 84
Reputation: 1509
Try this one
\$(.*?)*\$ Or (\$\w*\$)+
preg_replace('/\$(.*?)*\$/i', '1', '($commit$ + $Bug$)/$HR$*($Leader$^$IT$)');
1] Click Here
2] Better one
Check above links for answer
Upvotes: 0
Reputation: 2811
$str = '($commit$ + $Bug$)/$HR$*($Leader$^$IT$)';
$str = preg_replace('/\$(.*?)\$/', '1', $str);
echo $str;
Upvotes: 0
Reputation: 336098
$result = preg_replace(
'/\$ # Match $
\w+ # Match one or more alphanumeric characters
\$ # Match $/x',
'1', $subject);
This assumes that only the characters [A-Za-z0-9_]
are legal between $
and $
.
Upvotes: 2