Using regex in find/replace

I am working on a nodejs/express project which have a deprecated way of accessing request parameters :

req.param('parameter') instead of the valid req.params.parameter.

There is a lot of occurence in the project and I need to fix it. My question is how can I do to find the string's start "req.param('" until the string's end "')", extract parameter from the result, and then replace to have req.params.parameter ?

find:
req.param('str')
replace:
req.params.str

NOTE : Following the validated answer, to reverse this replace pattern, use :

(req\.params\.)([^; \n]+)

Answers


In the find and replace box (ctrl+h) you can insert as the search regex:

(req\.param)\('([^']+)'\)

and replace it with

$1.$2

Explanation: The first group (req\.param) is accessed via $1 and you could also change it to match more prefixes. Afterwards open a paren and a string. In the second group ([^']+) everything except a string closing char is matched. And afterwards the string and the paren is closed.


Need Your Help

Binding an Ancestor not working WPF

wpf binding ancestor

I've got a TreeView, which is modified to show Images in front of the text too. So my modified TreeViewItem is called ImagedTreeViewItem.