Page 1 of 1
Regex to replace C++ comment with C comment ?
Posted: Wed Jun 25, 2008 2:51 pm
by sergeant
Hello,
is it possible to replace all C++ comments (//) within a C-sourcecode with C comments (/* ... */) using Textpad regex?
(I'm using Textpad 5.2)
Thanks for any hint.
sergeant
Posted: Wed Jun 25, 2008 8:02 pm
by gan
Yes you could search for:
and replace with:
But since the /*....*/ can span several lines this might not be the result you want.
Let's say you have the following lines:
Code: Select all
//comment 1
//comment 2
//comment 3
HKEY hk; //comment 4
Using the regex example above it will be like this:
Code: Select all
/*comment 1*/
/*comment 2*/
/*comment 3*/
HKEY hk; /*comment 3*/
The example given above there are 3 lines in a row which is comments only and then it would make more sense to start with /* before comment 1 and end with */ after comment 3 instead of starting and ending the comment for each line. Using regex i cannot see how this could be done though since the // is for a single line only.
I guess it would be better if regex could change it into this, but i don't think that is possible:
Code: Select all
/*comment 1
comment 2
comment 3*/
HKEY hk; /*comment 3*/