Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Re: regex needed with match operator

by hardburn (Abbot)
on Apr 28, 2003 at 14:07 UTC ( [id://253699]=note: print w/replies, xml ) Need Help??


in reply to Re: regex needed with match operator
in thread regex needed with match operator

/\/(\w+)\/foo$/

Perhaps better as:

m!/([^/]+)/foo$!

Advantages:

  • Uses "choose your own quotes" to avoid falling-toothpick syndrome.
  • Some systems allow some funky characters that \w won't match. However, '/' certainly won't be in a filename (unless something really, really weird happens).

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re^3: regex needed with match operator (forbidden chars in filenames)
by Aristotle (Chancellor) on Apr 28, 2003 at 18:57 UTC
    In fact, the null byte is the only character you can expect not to show up in file names; on Unixoid and DOSish systems, the slash is also guaranteed not to appear, unless maybe you're working with a shot filesystem (I don't think we need to discuss that case). DOSish systems impose a whole lot of additional restrictions of course; none of those exist on Unixoid systems. On other systems than those, all bets are off; I wouldn't be surprised if the slash was a valid part of filenames on something "weird" like VMS.

    Makeshifts last the longest.

      By "slash", I think you meant only forward-slash '/' since '\' is legal for my UFS (OpenBSD) file system and I recall that its fine for Linux (when I last used it eons ago). Both '/' and '\' are illegal for the various Microsoft filesystems. Both '/' and '\' are legal in the Mac file systems except there ':' is reserved. *grin* aint it fun? I just use File::Spec and hope for the best.

        Yes, I meant forward slash, which is what slash usually means - the other one is called backslash, after all. And yes, I knew the colon is reserved on Mac (as it is on DOSish systems, btw), though I wasn't sure about the slash being legal. At any rate, yeah, that was my point. You can only rely on the nullbyte being illegal.. on most systems that commonly run Perl the slash is also, but even that's already not fully portable anymore.

        The only thing I hate about File::Spec is its (IMHO) misguided attempt to reduce namespace clutter and forcing a lot of typing on the user instead. Of course there's File::Spec::Functions.. what a mess. </rant>

        Makeshifts last the longest.

      On other systems than those, all bets are off; I wouldn't be surprised if the slash was a valid part of filenames on something "weird" like VMS.

      Nope. VMS is very strict unless things changed in ODS-5 (I haven't worked with V7). ODS-2 only allows upper case alpha, numeric, dollar sign, underscore and hyphen. Slashes in either direction are definitely out. Filenames can have a 39 character name and a 39 character type separated by a period. Older versions of VMS only allowed 9.3 filenames.

      90% of every Perl application is already written.
      dragonchild

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://253699]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-03-28 14:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found