Pattern: Comment

“Comment” is one of the patterns that you can select on the Match panel. With this pattern you can insert actual comment code into your comment.

  1. Click the New Formula button on the top toolbar to clear out all settings on the Samples, Match, and Action panels.
  2. On the Samples panel, paste in one new sample with some sample code:
    // Single line comment
    /* Multi
       line
       comment */
    /* No /* nesting */
    Not a comment
  3. On the Match panel, set both “begin regex match at” and “end regex match at” to “anywhere”.
  4. Click the Add First Field button to add field 1.
  5. In the “pattern to match field” drop-down list, select “comment”.



  6. In the “comment style” drop-down list, select “C-style languages”. This covers many programming languages, including Java and JavaScript.
  7. On the Regex panel, select “Python 3.13” as your application, turn off free-spacing, and turn off mode modifiers. Click the Generate button, and you’ll get this regular expression:
    //[^\n\r]*+|/\*(?>.*?\*/)
    Required options: Dot matches line breaks.
    Unused options: Case sensitive; Exact spacing; ^$ don’t match at line breaks.
  8. The Samples panel now highlights the quoted strings in our sample code:
    // Single line comment
    /* Multi
       line
       comment */
    /* No /* nesting */
    Not a comment

The programming language you select for your comment style is completely independent of the target application or language that you generate your regular expression for. If you want the same regular expression to handle multiple comment styles then you can use an alternation field to match one of several fields that use the “comment” pattern with different programming languages.

Reference