regexp problem

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Lynn David Newton
Date:  
Subject: regexp problem
Greetings,

I need a (Perl) regular expression that lops the first
word off a string which could possibly (does, in fact)
include newlines.

In the problem in question, the string data should only
contain digits. What is happening is that something is
causing a string to look like this: "234\n234", a
duplicate of its original self, with a newline
inserted, and because it's necessarily a string for
various operational reasons, that's how it's being
written to a database.

I found this solution myself, a two-step operation.
Given that $id="234\n234":

$id =~ s/\D/ /g;
$id =~ s/\D.*$//g;

Works (I think).

The first line changes non-digit characters to spaces,
giving me an ordinary space-delimited string.

The second line swacks off everything at the end
starting from the first non-digit character.

In the other solutions I tried, I couldn't deal with
the newline.

Maybe someone can see a simpler solution.

Extra credit with the usual PLUG prize goes to someone
who can generalize it so that it works with a string of
any type, i.e., to produce just the first "word" of the
original string, i.e., everything up to the first space
or newline, with the rest discarded.

Thanks.

--
Lynn David Newton
Phoenix, AZ