Greetings all,
If your file is small you could always read it in as a string and then ignore the newlines "\n" by using the s modifier.
Here is my example sans relevant error checking... I made a plain text file with your original posted data for testing (That is what the your_file is referring to)
#!/usr/bin/perl -w
use strict;
unless (open(F,'./your_file')){
die "Unable to open file for reading $!";
}else{
my $file_str = join("",<F>);
close F;
if($file_str =~ m/^(\.subckt.*?)x00/s){
my $match_str = $1;
print $match_str."\n";
}else{
print "No match for you!";
}
exit;
}
__OUTPUT__
.subckt cct0 v0 v1 v2 v3
+ v4 v5 v6
* useless comment
+ v7 v8 v9
+ va vb
A little explaination.
The 'm/^(\.subckt.*?)x00/s' is matching as if the string were a single line so \n's are ignored (or included with '.' however you look at it you can match across newlines with the 's' modifier), the '.*?' is doing a non-greedy match, without the '?' the '.*' would match as much as possible, this really only matters when you have the same pattern present in your search and you want to limit which one the regexp stops at.
hope that helps.
-injunjoel
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.