0

I am creating a small library for parsing XML documentation in Javascript files in the following format:

/// <doc type="function" name="parse">
///     <summary>Parses javascript documentation</summary>
///     <param name="js" type="string">Javascript input</param>
/// </doc>
var parse = function(js) { ... };

/// <doc type="string">
///   <summary>Holding the version of our library</summary>
/// </doc>
var VERSION = '0.0.1';

I have to create a regular expression that returns the content between the and tags. I've tried the following regular expression but it failed:

var xmlComments = js.match(/ \/\/\/(\s)<doc(.*)>(.*)<\/doc>/gi /);

But the match did not work, I hope someone can help me with this regular expression, thanks.

1
  • How do you invoke parse? In other words: how do you get the doc comment from the source? Commented Feb 4, 2013 at 19:46

1 Answer 1

1

If you are trying to get the content between the opening and closing doc tags, you could use

/<doc[^>]*>([\s\S]+?)<\/doc>/gi

where [\s\S] is any character including newlines ( . will not match newlines ).

For example

var xmlComments = [],
    regex = /<doc[^>]*>([\s\S]+?)<\/doc>/gi,
    match = regex.exec( js );

while ( match != null ) {
    xmlComments.push( match[1] );
    match = regex.exec( js );
}

where js is the file as a string.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.