Reputation: 544
I'm exploring regex, but I simply could not achieve exactly what I want yet. I'm using NetBeans and I need to swap all strncpy(... , sizeof(x))
to strncpy(... , sizeof(x) -1 )
, i.e, add the "-1"
between the last parenthesis.
An example should be:
strncpy(data->error, t_result[ID(data->modulo)].status, sizeof(data->error)); //need below
strncpy(data->error, t_result[ID(data->modulo)].status, sizeof(data->error) - 1);
Upvotes: 0
Views: 277
Reputation: 22817
(strncpy\(.*?sizeof\([^)]*\))
(strncpy\(.*?sizeof\([^)]*\))
Capture the following into capture group 1
strncpy\(
Matches strncpy(
literally.*?
Matches any character any number of times, but as few as possiblesizeof\(
Matches sizeof(
literally[^)]*
Matches any character except )
any number of times\)
Matches )
literallyReplacement $1 - 1
Result in:
strncpy(data->error, t_result[ID(data->modulo)].status, sizeof(data->error) - 1);
Upvotes: 1