I pasted your regex into my script exactly and it didn't work either :(. I found one that did, though.
     First, I want to make sure I understand yours. Please tell me if the following is correct...
/^PH(?:.{0,4}|.*(?![HI]-000).{5})$/
- starts with PH
- (?:)these parentheses aren't memory parentheses
- followed by 0 to 4 of any character or zero or more of any character
- (?!)return true if "H-000" or "I-000" would not match next
- followed by 5 of any character
- followed by the end of the line
     At first, I thought it failed because of the
.{5} part. So, I changed it to
{4,5} because the possibilities are "?H-000" (only 4 characters after the H) or "I?-000". That still didn't work. I was confused about why you used the (?:) and the quantifier and the or after the first wildcard dot, so I removed them. It still didn't work.
     After all that I re-started. I counted the characters between the PH and the part I wanted to check (\d{19}) and tried
/^PH\d{19}[^I][^H]-000$/. It's a little easier because all of these files have a fixed format. That did work, but I wasn't sure I needed to quantify the characters between the PH and the end of the file name. So, I ended up with
/^PH.*[^I][^H]-000$/ which works fine.
     I'm not sure why I couldn't get yours to work. I haven't used regex extensions or assertions before, so I want to understand them better.
Many thanks for your input.
Invulnerable. Unlimited XP. Unlimited Votes. I must be...
        
GhodMode
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.