Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

ilcylic's scratchpad

by ilcylic (Scribe)
on Jun 04, 2004 at 18:05 UTC ( #361063=scratchpad: print w/replies, xml ) Need Help??

23 Feb 2013

I've got a file with a bunch of lines that look like so:

Honda   CB1000  1995    26      47      15      99-3520-5       30      55      17      99-3519-5

and some lines that look like:

Yamaha  YZF-R1 Limited edition  2006    30      47      12      99-3540-5       30      55      17      99-3519-5

I'm trying to grab everything up to and including the year.
Thus far I have
cat triple_swap_bearings.txt | perl -ne 's/(^[^\s]*\s*[^\s]*\s*[\w\d\ +]*?(?=\d\d\d\d\s*\d\d\s*\d\d)\s*\d\d\d\d)\s*\d\d\s*\d\d.*$/\1/; print +;'

which fails on the lines that have the "extra stuff" after the model name, and before the year.

I suppose I don't need the [^\s]*\s*[^\s]*\s* though I was working on the "say what you really really mean in regex" principle there.

What I need to say in regex is "Match things which are not four digits followed by some amount of whitespace followed by two more digits".

cat triple_swap_bearings.txt | perl -ne 's/(^[^\s]+\s*[^\s]+\s*[\w\d\ +\-\(\)\&\/]+?(?=\s+\d\d\d\d\s+\d\d\s+\d\d)\s+\d\d\d\d)\s+\d\d\s+\d\d. ++$/\1/; print;'

(Note the addition of \s+ inside the positive lookahead assertion.)

Date Unknown:

if ($foo == 1) { my $bar; unless(($bar = $socket->read()) =~ /one/) { die $bar, $!; } $socket->write('foo'); unless(($bar = $socket->read()) =~ /two/) { die $bar, $!; } $socket->write('bar');
etc. vs:
if ($foo == 1) { unless((my $bar = $socket->read()) =~ /one/) { die $bar, $!; } $socket->write('foo'); unless((my $bar = $socket->read()) =~ /two/) { die $bar, $!; } $socket->write('bar');
Log In?

What's my password?
Create A New User
[Discipulus]: good night monks!
[shmem]: LanX: oh... now I have to figure out if this is good or bad news.
LanX bad day monks ?
[LanX]: hope you find sleep
[shmem]: LanX: which one?
[LanX]: the last
Discipulus yes a very bad day
[shmem]: grandola, vila morena
[shmem]: LanX: ah, that one. You'll get the bug reports also :P
[Discipulus]: upvote me! i'll make pm great again! ;=)

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2017-04-29 22:43 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (534 votes). Check out past polls.