all quantifiers (ie * + {2,7} ) are all "greedy" which means they will try
to match as much as possible as long as it's true.
To make the quantifier not "greedy" put a ? (question mark) after it, then
it will match the least as possible as long as it's true.
what you want is
$String =~ /^(.*?):/;
now $1 is everything up to the first : excluding the colon.
-----Original Message-----
From: Russ Foster [mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 14, 2002 5:10 PM
To: '[EMAIL PROTECTED]'
Subject: Regular Expressions - matching the first time
I have string, something like:
$String = "aaa bbb: fffd: sdfsdf qweqd: adfsdf qwcdsfs: qwdq qchuti:
qwiojd";
Now, I want to extract everything from the start of the string, up through
the FIRST colon ":" -- in this case "aaa bbb". My regex looks like this:
$String =~ /^(.*):/ ;
So: ^ starts at the beginning, (.*) to grab everything in the middle, and :
to match the colon.
What I am getting is, everything from the start of the string up until the
last colon. In this example:
$1 = "aaa bbb: fffd: sdfsdf qweqd: adfsdf qwcdsfs: qwdq qchuti"
What I want is:
$1 = "aaa bbb"
I even tried using:
$String =~ /^(.*):{1}/ ;
Thinking the {1} would match the first occurance of :, but that didn't
change the results (I was runningn out of ideas).
Now, I could split $String on :, but I have to think that there is a better
way and I'm missing some modifier that I can't find in the FAQ or any of the
three books that have been dumped on my desk.
Any help is appreciated.
Russell J Foster
Subject, Wills, & Company
e. [EMAIL PROTECTED]
v. 630-572-0240
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
----------------------------------------------------------------------------
--------------------
The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]