Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Regex needed :<

by kennethk (Abbot)
on Jan 22, 2015 at 16:08 UTC ( [id://1114155]=note: print w/replies, xml ) Need Help??


in reply to Regex needed :<

Flip-flop in either configuration is probably the more natural choice, but a regular expression was the spec, so I give you:
#!/usr/local/bin/perl use strict; use warnings; $_ = <<'EOT'; // useless comment Some Code //********************************************************** // //I need that text // And that also // //********************************************************** Some Code //********************************************************** // //I need that text // And that also // //********************************************************** Some Code // useless comment Some Code //********************************************************** // //I need that text // And that also // And some more // //********************************************************** Some Code // useless comment EOT my $i = 0; while (m|^//\*+\s*^.+?(\w[^*]+\w).+?^//\*+\s*$|smg) { printf "%d:\n%s\n\n", ++$i, $1; } __END__ 1: I need that text // And that also 2: I need that text // And that also 3: I need that text // And that also // And some more
There's no way in a single autonomous expression to grab a variable number of fields, so I had to grab the whole chunk. If you know each one is 2 lines, you could use
^//\*+\s+^.+?^//\s*(\w.+?)\s*^//\s*(\w.+?$).+?^//\*+\s+$

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1114155]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-24 17:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found