I've been trying various regex expressions but so far in vain.
How do I change lines like this:
/*Set volume to 20*/
to this:
// Set volume to 20
IOW replace '/*' by '// ' (note the space), and delete '*/'
Stumped over this one
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
-
- Posts: 2457
- Joined: Sun Mar 02, 2003 9:22 pm
Thanks! Saw your impressively fast reply as I was coming back to proudly present the solution I came up with:
Seemed to work on first tests. Does that look reliable?
Code: Select all
Find what: (/*)(.*)(*/)
Replace with: // 2
-
- Posts: 2457
- Joined: Sun Mar 02, 2003 9:22 pm
There's a bug in the current version of the software that runs these forums. Single backslashes in posts get swallowed, so you have to double them. Your example should look like this:
Yes, that works. But the first and third pairs of parentheses unnecessarily capture text that is discarded. Also, unlike the version I gave, it captures comments that aren't at the beginning of a line.
And in a TextPad replacement expression \2 means the same as $2 .
Code: Select all
Find what: (/\*)(.*)(\*/)
Replace with: // \2
And in a TextPad replacement expression \2 means the same as $2 .
-
- Posts: 2457
- Joined: Sun Mar 02, 2003 9:22 pm
If the original comments can occur anywhere in a line, perhaps followed by further text on the same line, then the replacement will change
to
which is plainly wrong.
What spec?
Code: Select all
/* Unhelpful comment */ doEssentialThing () ;
Code: Select all
// Unhelpful comment doEssentialThing () ;
What spec?
How about lines that have multiple comments? Such as:
Also all regex patterns also match empty comments and I just cannot imagine any code that ever makes use of such. Let alone the void sense of turning that into another comment:
Code: Select all
if( /*bOne and bTwo and*/ bThree /*and bFour*/ ) {
Code: Select all
/**/