2

I want to alter thousands of lines in a project, the line is always one of these formats and is always in the middle of a line.

link() accepts upto 3 parameters and can look like these:

$this->url->link('this/path')
$this->url->link('this/path', '', true)
$this->url->link('this/path', 'something=' . $something, true)
$this->url->link('this/path', 'something=' . $something . '&other=' . $other, true)

I have a put together the following regex which correctly finds the lines I want as set out above with no problem.

// regex
\$this->url->link.*(, true)

I want to be able to remove empty parameters from the line so basically this means:

If parameters two and three match '', true remove them, otherwise remove just paramter three: , true

I tried these:

\$this->url->link.*(.*)
\$this->url->link.*($1)

1 Answer 1

1

If I've understood your question, I'd use 2 different replacement operations, one to remove '',true and another to remove ,true.

deleting '', true

Search: \$this->url->link\((.+), '', true\)
Replace: \$this->url->link($1)

This should replace
= $this->url->link('some/thing', '', true)
with
= $this->url->link('some/thing')


deleting , true

Search: \$this->url->link\((.+),(.+), true\)
Replace: \$this->url->link($1,$2)

This should replace
=> $this->url->link('some/thing', 'variable data or empty', true)
with
=> $this->url->link('some/thing', 'variable data or empty')

and also works for
$this->url->link('some/thingthing', 'variable data', true)
replacing it with
$this->url->link('some/thingthing', 'variable data')

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

5 Comments

Be extremely careful with mass replacements though, this shouldn't need to be said, but i feel like it's important enough to say anyway.
I have updated my question with real data, hopefully that will help, I think you were understanding my question just not with the right data. Sorry about that.
I fixed the answer, it was missing the backslash on the replace lines, also the '' is the same in both so no need to be replaced, so i removed them from search and replace so they are picked up automatically instead. Thank you very much for your answer, it really helped.
as far as i remember, the replace lines don't need backslashes, i might be wrong though.
It did for me, the line shows red without it, I am using NB8.2 / Ubuntu 16.04 it could just be a distro matter. In any case, it did work with the replace backslash so all is now done.

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.