Search code examples
javascriptregexdocblocks

Match PHPDoc comments with Regex


I use the Javascript Syntax Highlighter built by Alex Gorbatchev

https://github.com/alexgorbatchev/SyntaxHighlighter/

I am trying to add support for PHPDoc comments, the PHP brush currenty matches singline and multiline comments but inside of comments when there is something like @author I would like to wrap that in a seperate class like other Syntax editors do.

I am trying to use this Regex

"\\s@[A-Za-z]+"

I tried testing it here http://regexpal.com/?flags=ims&regex=%22%5C%5Cs%40%5BA-Za-z%5D%2B%22&input=%0A%40author%0A

But I cannot tell if it is working, can someone help me or let me know if that will match correctly


Solution

  • The regex you're after is:

    "\\s*@[A-Za-z]+"
    

    Note the * after the \s (0 or more whitespace characters).

    Additionally, RegexPal is not showing your match because it uses the literal regular expression, not the string version, so you should enter

    \s*@[A-Za-z]+
    

    in the top box, like this example. Note how the matched portion of the lower box is highlighted.