Tomás Rodrigues
Tomás Rodrigues

Reputation: 544

Netbeans regex - Find and Replace (Ctrl + H)

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

Answers (1)

ctwheels
ctwheels

Reputation: 22817

See regex in use here

(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 possible
    • sizeof\( Matches sizeof( literally
    • [^)]* Matches any character except ) any number of times
    • \) Matches ) literally

Replacement $1 - 1

Result in:

strncpy(data->error, t_result[ID(data->modulo)].status, sizeof(data->error) - 1);

Upvotes: 1

Related Questions