1

I want to replace

$this->input->post("product_name");

with

$post_data["product_name"];

I want to use notepad++ regex, but I couldn't find proper solution

In find --> $this->input->post("[\*w\]"); In replace --> $post_data["$1"];

but its not working

1
  • You are referencing a matching group ($1) that you did not create. Pu parenthesis outside the *w to match that word and pass it to the replace stage Commented Apr 9, 2019 at 9:44

3 Answers 3

1

The $this->input->post("[\*w\]"); pattern does not work because:

  • $ is a special char matching the end of a line, you need to use \$ to match it as a literal char
  • [\*w'\] is a malformed pattern as there is no matching unescaped ] for the [ that opens a character class. Also, w just matches w, not any letter, digit or underscore, \w does that.

You may use

Find What: \$this->input->post\("(\w*)"\);
Replace With: $post_data["$1"];

If there can be any char inside double quotes use .*? instead of \w*:

Find What: \$this->input->post\("(.*?)"\);

Regulex graph:

enter image description here

NPP test:

enter image description here

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

Comments

0

Use this pattern to match desired text \$this->input->post\(("[^"]+")\);

And replace it with pattern \$post_data\[\1\]

Explanation:

\$this->input->post - matach $this->input->post literally

\(("[^"]+")\); - match (literally, then match double quates and everything between them with "[^"]+" and store inside first capturing group, then match ); literally

enter image description here

Comments

0
  • To replace

$this->input->post("product_name");

by

$post_data["product_name"];

do replace, with regex activated

this->input->post\("(.*)"\);

by

post_data\["\1"\];

  • The \x with x a number, corresponds to the x-th match catched with the parenthesis. Here we catch any character inside this->input->post(XXXX);

  • Don't forget to escape special character with \. Your special characters were []()

Comments

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.