1

I am trying to replace an entire string in a file.

$db['default']['hostname'] = 'localhost';

I want to do a preg_replace the entire string, even the variable. Im having trouble matching it with the RegEx. I have this so far:

preg_match("/\$db\['default'\]\['hostname'\]^;");

But what Im trying to do is find the entire line and completely replace it with something else. So the Regex would be like:

"^$db['default']['hostname'](AnythingHere);$"

Does anyone know the character group I accomplish that?

1 Answer 1

2

This one worked on RegexPal:

(\$db\[\'default']\['hostname'])( = 'localhost')(;)

And the replace string should be:

\1(AnythingHere)\2

Example

Sign up to request clarification or add additional context in comments.

1 Comment

+1 for a working solution. You could also use non-matching look-ahead patterns for the bits that aren't going to be replaced.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.