I am new to regular expressions. I am looking for something that can help me do a find and replace throughout our entire code tree with any function that creates a file descriptor.
For example, I need to change socket(PF_LOCAL,SOCK_STREAM, 0) to socket(PF_LOCAL,SOCK_STREAM | SOCK_CLOEXEC, 0)
In each case I am appending to the end of the second argument, but I do not know how long the current second argument is going to be or what text it will contain. I am thinking the best way to do it is to find the second comma and replace that with my string (" | SOCK_CLOEXEC,")
If someone could give me and example of this it would be extremely helpful. Thanks
I’m not totally sure if this is what you’re looking for but in perl:
Which means:
s/to_substitute/substitution_string/“Find patternto_substituteand replace it withsubstitution_string“And I used:
[^,]+which means “string without comma”.()which are used to capture strings which are copied in substitution string with$1,$2,$3.I hope this helps.