regexp problem
der.hans
plug-discuss@lists.plug.phoenix.az.us
Wed, 11 Dec 2002 17:18:39 -0700 (MST)
Am 11. Dec, 2002 schw=E4tzte Lynn David Newton so:
> 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.
Just for something different...
$ cat /tmp/anke
234\n234
5643\n5634
1984\n2112
$ perl -e '($muell,$_) =3D split( /\\n/, $_, 2 );' -p /tmp/anke
234
5634
2112
> 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.
Change \\n to be whatever you want to split on.
ciao,
der.hans
--=20
# https://www.LuftHans.com/ http://www.TOLISGroup.com/
# Nobody grows old merely by living a number of years.
# We grow old by deserting our ideals.
# Years may wrinkle the skin, but to give up enthusiasm
# wrinkles the soul. -- Samuel Ullman