Jump to content

Regex Pains


Kovo

Recommended Posts

Hello all,I really tried hard to avoid asking on the forums, but after an hour, I just cant get this to work and its bugging me.I want to know if someone can help me out with the regex I need to find the folliwng in a string and replace it (using PHP)

$current=preg_replace("/\bdefine('HOST_NAME','');\b/","define('HOST_NAME','".$HOST_NAME."');",$current);

Heres my problem: define('HOST_NAME','') can either have an empty value as the example above, or something already set like so:

define('HOST_NAME','a host name');

So obviously my current preg_replace function wont work al lthe time (or at all)Any help would be greatly appreciated!

Link to comment
Share on other sites

There's another mistake: parenthsis are reserved characters and should be escaped.You can just check for 0 or more characters if there may or may not be a host name already:/\bdefine\('HOST_NAME','[^']*'\);\b/

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...