in reply to Re^4: Pattern Matching in Arrays
in thread Pattern Matching in Arrays

I liked the split method recommended above.

Unfortunately it doesn't work with multiple underscores.

If you want to stick with regexp, then try this:

if (/^(.*?)(?:_([^_]*))?\.pdf$/) { # do something with $1 and $2 }

Replies are listed 'Best First'.
Re^6: Pattern Matching in Arrays
by aj.kohler (Initiate) on May 13, 2009 at 18:28 UTC

    Let me try explaining the overall goal of the program:

    1. Read in directory of file names

      1. Most file names hava a Root number, Revision, Extension of pdf: 12345_-v1.pdf
      2. Most names have an underscore as the seperator between Root Number and Revision: 3873215a_-v1.pdf
      3. Many names have more than 1 underscore used as text seperators: 21586_rework_bore_tool_-v2.pdf
      4. Some names have no underscores in them: 4148-t-2.pdf
    2. I need to display only the latest revision of the file, so if the following exist in the directory:
      21586_rework_bore_tool_-v1.pdf
      21586_rework_bore_tool_-v2.pdf

      Only display 21586_rework_bore_tool_-v2.pdf
    3. I am unable to capture all of the combinations listed above...

    I appreciate all recommendations...

    AJ