Jump to content

Regex Pains


Kovo
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...