I'm fairly new to regular expressions and what I'm trying to achieve seems impossible after a few hours of trying. I could not find similar issues, so that is why I am making a separate question; please excuse me if there is already a question like that.
Now. I want to match every occurrence of the regular expression throughout the document; the occurrences are spanning multiple lines. Here is an example:
// javascript.js
/**
* #start?
* @name myFunction(p1)
* @desc Description of the function
* @param p1 : int = Parameter of type int
* ...
* #end?
*/
function myFunction(p1) { ... }
/**
* #start?
* @name yourFunction()
* @desc Description of the function
* ...
* #end?
*/
function yourFunction() { ... }
With the regular expression I would like to match the comment sections that describe the functions, from #start?
to #end?
. As a result I want to have 2 matched occurrences - the description of the first function and that of the second one.
What I came with is (#start\?)[\s\S]+(#end\?)
, but as you can guess it matches the first #start?
and closes the match with the second #end?
How can I make it match all similar comment sections as separate occurrences?
Thank you very much for your time!
Update/Solution
As pointed out by Wiktor Stribiżew - lazy != greedy The working regular expression for this case is (#start\?)[\s\S]+?(#end\?)