Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: regular expression

by McDarren (Abbot)
on Feb 28, 2010 at 05:51 UTC ( #825734=note: print w/replies, xml ) Need Help??

in reply to regular expression

my $string = '~/tmp/hfj/abc/bhd/5009.xmlreal.xml'; $string =~ s/^.*\/\d+//; print "$string\n";

Another way is to use File::Basename to extract the file name, and then remove the bits you don't want.

use File::Basename; $string = '~/tmp/hfj/abc/bhd/5009.xmlreal.xml'; my ($filename, $directories, $suffix) = fileparse($string); $filename =~ s/^\d+//; print "$filename\n";


Replies are listed 'Best First'.
Re^2: regular expression
by AnomalousMonk (Chancellor) on Feb 28, 2010 at 05:57 UTC

    I don't understand the purpose of the /g regex modifier in the above regex.

      heh.. it serves no purpose whatsoever.
      I'll remove it. Not quite sure what I was thinking about there :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://825734]
[Eily]: oh, boolean context uses the "" overload if no bool overload has been defined
[Eily]: (I wondered if overloading bool was actually necessary)
[Corion]: Yeah, you need bool to get a true value, and the rest to return the other value ;)
[choroba]: perl -wE '{package o; use Tie::Scalar; use parent -norequire => "Tie::StdScalar" ;sub FETCH { "x" x int rand 2}} tie my $x, "o" ; say $x for 1 .. 10'
[choroba]: for complete ness

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2017-07-27 13:52 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (414 votes). Check out past polls.