COOLak
COOLak

Reputation: 399

Backreference only replaces a pattern with one symbol

I need to replace all $postData[some_text] with $postData['some_text'].

I tried looking for (\$postData\[)+([a-zA-Z_+])+(\]) and replacing with $postData['$2'] but it only replaces some_text with 't' i.e. the last letter of some_text. I don't get it, how do I keep the whole text?

Upvotes: 0

Views: 28

Answers (1)

Scott Weaver
Scott Weaver

Reputation: 7361

Put the quantifier inside the parentheses so you capture everything:

\$postData\[+([a-zA-Z_+]+)\]

replacement pattern:$1

regex101

Upvotes: 2

Related Questions