Including * / in C-style block block comments

Is there a way to include * / in a C-style block comment? Changing a block comment to a series of comment lines (//) in this case is not an option.

Here is an example of the type of comment causing the problem:

/** * perl -pe 's/(?<=.{6}).*//g' : Limit to PID */ 
+4
source share
5 answers

Normally, comments should not be literal, so this is all too common.

You can wrap it all in a #if block:

 #if 0 whatever you want can go here, comments or not #endif 
+24
source

Nope! This is not true.

+10
source

You can block the problem by confusing your regular expression so as not to include an offensive character sequence. In terms of what you are doing, this should work (make * non-living):

 /** * perl -pe 's/(?<=.{6}).*?//g' : Limit to PID */ 
+3
source

In general, you cannot.

Here is a tricky answer that works in this case:

 /** * perl -pe 's/(?<=.{6}).* //gx' : Limit to PID */ 

This (or it must have been, I really did not check the perl command) is a regular expression that matches the original, because the x modifier allows you to use a space for clarity in the expression, which allows * for the branch from / .

You can use more spaces, I included only one space that breaks the end of the comment block token.

Some compilers support the ability to include a custom function for resolving nested comments. This is usually a bad idea, but in this particular case you can also do

 /** * /* perl -pe 's/(?<=.{6}).*//g' : Limit to PID */ 

with this option is enabled only for this source file. Of course, as the funky coloring in the above fragment shows, the rest of your tools may not know what you are doing, and will make the wrong guesses.

+2
source

In this particular case, you can change the delimiter in your perl regex. You can use any non-alphanumeric, non-space separator. Here I switched to # :

 /** * perl -pe 's#(?<=.{6}).*##g' : Limit to PID */ 

Common options: # and % .

Bracketing characters, such as parsers or curly braces, get a slightly different syntax because they are expected to be paired pairs:

 /** * perl -pe 's[(?<=.{6}).*][]g' : Limit to PID */ 
0
source

All Articles