'RegEx: how to batch delete virtual keyword in derived method by Regex?
I'm trying to delete the virtual keyword in the derived method which is an override. Should I use virtual, override, or both keywords?
now I have the several scenario:
virtual void test1() const override;
virtual int test2() override { xxx }
virtual void test3(int p1,
int p2,
int p3) const override;
virtual void test4(int p1,
int p2,
int p3,
int p4) const override;
virtual void testn(int p1,
int p2,
int p3,
int p4,
......,
int pn) const override;
--> I need to delete the virtual keyword for the whole project code(hundreds of files)
void test1() const override;
int test2() override { xxx }
void test3(int p1,
int p2,
int p3) const override;
void test4(int p1,
int p2,
int p3,
int p4) const override;
void testn(int p1,
int p2,
int p3,
int p4,
......,
int pn) const override;
Because there are lots of places that need to modify, I plan to use RegExp to do it. I try the following RegExp:
\bvirtual\b.*\s.*\s.*\s.*\s.*\s.*\s.*\boverride\b
but it seems \s.* need to know the number, is there anyone familiar with RegExp who can help me how to write the expression? and also how to replace and delete the virtual keyword by RegExp? [![enter image description here][1]][1]
Solution 1:[1]
Consider
virtual void test1() const override;
virtual int test2() override { xxx } //an example of commentary
virtual void test3(int p1,
int p2,
int p3) const override;
virtual void test4(int p1,
int p2,
int p3,
int p4) const override;
virtual void testn(int p1,
int p2,
int p3,
int p4,
......,
int pn) const override;
and regex
\bvirtual\b\s*(.+?)\s*\boverride\s*(.+?)
the regex flags are /gms.
The result is
void test1() const;
int test2(){ xxx } //an example of commentary
void test3(int p1,
int p2,
int p3) const;
void test4(int p1,
int p2,
int p3,
int p4) const;
void testn(int p1,
int p2,
int p3,
int p4,
......,
int pn) const;
Please, use this regex 101 link for further details and explanation, if needed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jarod42 |
