Reputation: 2474
I am looking to match strings out of a file that are prefixed
/**
and have a postfix
*/
With any number of characters/whitespace/newlines in between.
eg:
/** anything
anything
*/
I have m/(\/\*\*).*?(\*\/)/
so far, however this does not handle newlines. I know the fix has to be simple, but i have very limited regular expressions experience.
Bonus question: Does anyone have a good website for learning regular expressions?
Upvotes: 0
Views: 295
Reputation: 103714
Your specific regex (with newlines) can be matched with \/\*\*[\d\D]*?\*\/
A side effect of \D
is that it matches newlines and can be used in this manner.
In Perl, you can also use Regexp::Common for finding a whole variety of source code comments.
There have already been mentioned some of the best links (Friedl's book and http://www.regular-expressions.info/)
My web sites for regex are these:
Upvotes: 0
Reputation: 317
Without using /s with make '.' behave differently, the following should work too:
m/(\/\*\*)(\r?\n|.)*(\*\/)/
For a place to learn perl?
http://perldoc.perl.org/ http://perldoc.perl.org/index-tutorials.html This is my ultimate reference, always.
But if you don't like to read something in a manual style which is a bit bore. Try Jeffrey Friedl's Mastering Regular Expressions from O'Reilly, which is more interesting.
http://oreilly.com/catalog/9781565922570
Upvotes: 0
Reputation: 170138
Add the s
modifier after it:
m/(\/\*\*).*?(\*\/)/s
But if it's source code you're operating on, be careful:
print 'a string /**';
int a = b + c;
print '*/';
// /**
a = a - c;
// */
There really is but one online resource if it comes to learning regex: http://www.regular-expressions.info/
Upvotes: 3