用preg_replace替换html中的值

I have:

value="my_string"

in my HTML

I want to change this to:

value="my_second_string"

I've tried

~[value="]*?["]~'

This is not working. Could someone please advise me

In regular expressions, [] creates a character class, so your original pattern will match any number v, a, l, u, e, =, or " characters (non-greedily) followed by a single " character.

You can use this pattern to match value="my_string":

 ~value="[^"]*"~

This will match a literal value=" followed by any number of characters other than ", followed by a single " character.