Reputation: 41
i have following string:
@c24-blue: #005ea8; @c24-green: #737948;
Now i want to replace the definition of @c24-green to #fff.
I have tried it over:
$string = '@c24-blue: #005ea8; @c24-green: #737948;';
$string = preg_replace('/([@c24-green:]) (.*);/', '$1' . ' #fff;', $string);
The result should be:
@c24-blue: #005ea8; @c24-green: #fff;
Is there a solution to get this working?
Regards, Kai
Upvotes: 0
Views: 39
Reputation: 13640
Remove your string "@c24-green:"
from character class, following should work..
(@c24-green:) (.*);
^ ^
$string = preg_replace('/(@c24-green:) (.*);/', '$1' . ' #fff;', $string);
See DEMO
Edit: If you want to make it generic.. you can use the following:
(@[^:]*:) ([^;]*);
See DEMO
Upvotes: 1
Reputation: 91373
How about:
$string = preg_replace('/(@c24-green:)[^;]+/', '$1 #fff', $string);
Upvotes: 1