0

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...

0

3 Answers 3

2
$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 $.

Sign up to request clarification or add additional context in comments.

Comments

0

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

4 Comments

Sorry but check now its working now that's some string problem
@chintu: So 0 is not allowed inside the variable name? And $$$ or $´$ would be legal variable names? Strange...
What exact happen You can also try more better option here codepad.org/NvHl557l
Nice, edit your script to match my regex and you get the check. lol
0
$str = '($commit$ + $Bug$)/$HR$*($Leader$^$IT$)';
$str = preg_replace('/\$(.*?)\$/', '1', $str);
echo $str;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.