-2

I am trying to match multiline comments such as follows in source code:

    /**
     * Loads an {@link Ext.data.Model} into this form (internally just calls {@link Ext.form.Basic#loadRecord})
     * See also {@link Ext.form.Basic#trackResetOnLoad trackResetOnLoad}. The fields in the model are mapped to 
     * fields in the form by matching either the {@link Ext.form.field.Base#name} or {@link Ext.Component#itemId}.  
     * @param {Ext.data.Model} record The record to load
     * @return {Ext.form.Basic} The Ext.form.Basic attached to this FormPanel
     */
    loadRecord: function(record) {
        return this.getForm().loadRecord(record);
    },

/**
 * Convenience function for fetching the current value of each field in the form. This is the same as calling
 * {@link Ext.form.Basic#getValues this.getForm().getValues()}.
 *
 * @inheritdoc Ext.form.Basic#getValues
 */
getValues: function(asString, dirtyOnly, includeEmptyText, useDataValues) {
    return this.getForm().getValues(asString, dirtyOnly, includeEmptyText, 
  useDataValues);
},

which should return only the commented section(starting with /** and ending with */). So far I have the following:

^(\/\*\*)(.|\n)*$(\*\/)
Pepria
  • 394
  • 1
  • 8
  • 22
  • Never use `(.|\n)+?` that is a performance killer. Use my approach in the linked thread to avoid stackoverflow exceptions with your pattern in case of very long multiline comments. – Wiktor Stribiżew Nov 27 '17 at 07:51

1 Answers1

5

Here, try this:

(\/\*\*)(.|\n)+?(\*\/)

This should do exactly what you want it to do. The first capture group just matches the /**. The second group matches any other character and the + matches any number of that token. The ? makes the search lazy, matching only up to the next occurrence, so we don't match from the start of the first comment to the end of the second comment and everything in between.

Steampunkery
  • 3,839
  • 2
  • 19
  • 28