I’ve been trying to figure this out myself but I’m afraid Regular Expressions just aren’t my thing. In this sample string: “My name is %name and I live in $address.” I’m trying to get the words which begin with “%” then replace them with their values in $name or $address depending on what word was found in the regex. The new string is then returned complete with the replaced values.
Should not return words like: aaa%aaa (% isn’t the first character) and \%word (the % is escaped)
This is in PHP. I’m using this since I’m grabbing the data from a *.ini file where everything is a string. I remove the $_POST example so it’s not misleading.
This one should do fine:
However it’s usually a bad thing to not sanitize $_POST/$_GET before display/whatever.