I'm trying to find comment blocks in PHP source code using regular expressions in Python 3. The PHP comments are in this format:
/**
* This is a very short block comment
*/
Now I came up with the following regular expression:
'/**[.]+?*/'
I figure that -in combination with the DOTALL flag- should do it, but no. It doesn't find anything. Strange thing is that when I remove the trailing slash, like this:
'/**[.]+?*'
then it finds the following string:
/**
*
I have no idea why the regex can't find an asterisk followed by a slash... I checked the file that I'm searching to double check I didn't have a typo in the comment (I didn't).
Also a slash is no special character in regex, so I wouldn't have to escape it. (I tried, but it didn't help.)
Can anyone tell me what's wrong with my regex? :)
By the way, I also came across this! thread where someone tried to do the same in Java. The final winning answer finished his regular expression the same way I do now, so I'm clueless :( Could this be a bug in Python regex or am I completely missing something?
Any help is much appreciated! :D
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…