in reply to Re^2: Splitting an url in its components
in thread Splitting an url in its components

Well, you can special-case it, but then it'll only work for .tar.gz:
s{\.(?:tar\.gz|[^.]+)\z}{};

The problem is that, in general, you can't know from a file name which part of it is "extension" and which part is not, unless you either have a clear-cut definition of what "extension" means (I don't know any that satisfies your requirement), or you have a list of all possible extensions.

Replies are listed 'Best First'.
Re^4: Splitting an url in its components
by baurel (Sexton) on Jul 17, 2008 at 15:42 UTC
    this is great and exactly what I was looking for :-)

    for my personal learning purposes:

    I don't fully understand the expression "(?:tar\.gz|^.+)"

    - what does the part '?:tar\.gz' mean?

    thanks so far for your help
    ben
      There is no ?:tar\.gz part, because (?: ... ) has a distinct meaning (it's grouping without capturing), and tar\.gz just matches the string tar.gz.
      Use <c> code here </c> tags (Markup in the Monastery).

      Install YAPE::Regex::Explain, because

      use YAPE::Regex::Explain; print YAPE::Regex::Explain->new(qr~(?:tar\.gz|[^.]+)~)->explain; __END__ The regular expression: (?-imsx:(?:tar\.gz|[^.]+)) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- (?: group, but do not capture: ---------------------------------------------------------------------- tar 'tar' ---------------------------------------------------------------------- \. '.' ---------------------------------------------------------------------- gz 'gz' ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- [^.]+ any character except: '.' (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------