
shawnhcorey
Enthusiast

Jul 18, 2009, 4:28 PM
Views: 13644
|
Re: [bktanner] Brand new to regexp question
|
|
|
Also something else I am not quite clear on, and maybe this is a stupid question, but will this check every string in the file one line at a time and be able to locate a string in the form [#.#.#.#] Regardless of what else is on that line? I suppose what I am asking is if the file I am reading is something like: 1 blahblahblahblah [#.#.#.#] blahblah 2 blahblahetc.etc.etc.etc. 3 blahblahblahblah [#.#.#.#] etc. Will it be able to extract that string from each line, or does the file have to be of the form: 1 [#.#.#.#] 2 [#.#.#.#] 3 [#.#.#.#] I guess essentially what I am asking is, does this check every string on a line regardless of what all is on that line to check and see if the string is of that form, or will this only check one string per line? No, the code assumes only one [#.#.#.#] is on the line. This will extract multiple instances.
#!/usr/bin/perl use strict; use warnings; while( <DATA> ){ if( my @captured = $_ =~ m{ \[ (\d+) \. (\d+) \. (\d+) \. (\d+) \] }cgmsx ){ print "found @captured\n"; } } __DATA__ [0.0.0.0] this is a test [232.34.03489.238327983] [1.2.3.4] [1.2.3.4] [1.2.3.4] [1.2.3.4] [1.2.3.4] __END__ I love Perl; it's the only language where you can bless your thingy. Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib. Get Markup Help. Please note the markup tag of "code".
|