[TriLUG] regular expression

Benjamin Reed ranger at befunk.com
Thu Aug 16 13:52:42 EDT 2001


acoliver [acoliver at nc.rr.com] wrote:
> Hi all,  I'm not having a PERL day.
> 
> Any one of you regular expression gurus have the answer to this
> 
> If I have this (coming line by line from stdin):
> $linein = 01072001/string.189.123123
> 
> What would the regular expression be to suck out '189'?  The directory name
> is fixed length, the string is variable and the trailing numeric is
> variable.  The only thing I know in other words is I want to match
> everything between the two dots but not including them.

The simplest version would be:
	$linein =~ /\.(.+?)\./;

...but this depends on string not containing .'s (a period, followed by
one or more characters, followed by a period, putting the chars in $1)

A longer and more anal one would add forcing context in relation to the
numeric at the end of the line:
	$linein =~ /\.(.+?)\.\d+$/;

...that matches a period, followed by one or more characters, followed
by another period, and then one or more numeric values at the end of the
line.  If the bit between the period is always numeric, you can change
".+" to "\d+".

That should cover it.

-- 
Ben Reed a.k.a. Ranger Rick (ranger at befunk.com)
http://defiance.dyndns.org/ / http://radio.scenespot.org/
The devil's in the broad, sweeping generalizations.



More information about the TriLUG mailing list