It is important to show us the "crap" because that shows that you have at least made an effort. It is also important to show some of the data because a description may not be very clear. As you will have noticed from the earlier replies to your original message, we are inclined to grab an idea and run with it - even if it is hopelessly wrong.
After all that lecturing, here is a solution for you (I suggest you examine this carefully, then reply explaining how you think it works):
use warnings; use strict; while (<DATA>) { my $match = /(NP\s+)(U\s+)(Pu\s*)/i; last if ! ($_ = <DATA>); next if ! $match; chomp; my $NP = substr $_, $-[1], $+[1] - $-[1] + 1; my $N = substr $_, $-[2], $+[2] - $-[2] + 1; (my $Pu = substr $_, $-[3]) =~ s/(\s)//g;; $NP =~ s/(\s)//g; $N =~ s/(\s)//g; print "NP $NP, N $N, Pu $Pu\n"; } __DATA__ 000 NP U Pu 001 1.270000 000001 3.141000 002 Lev N Pu 003 0.13 000001 3.277118 004 NP U Pu 005 1.000220 000002 3.098761 006 Yac S Yb 007 10.33000 000001 90000000
Note that the sample data is given as part of the script so tht other monks can simply download the entire thing and run it to see that it works. The sample given prints:
NP 1.2700000, N 0000013, Pu 3.141000 NP 1.0002200, N 0000023, Pu 3.098761
In reply to Re^3: regex help!
by GrandFather
in thread regex help!
by igotlongestname
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |