Reputation: 1758
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]+)
Upvotes: 0
Views: 34
Reputation: 4847
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.
Upvotes: 1