"Much that I bound I cannot set free"
Much that I sought, I could not find.
Much that I found, I could not bind.
Much that I bound, I cound not free,
Much that I freed return to me. - Lee Wilson Dodd
ScottW blogs about an experience that he had today involving some help received on the regex list. I originally responded to Scott's cry for assistance with the following psuedo-example which used conditional matching logic:
- must have: \/Directory\/ - then can have a folder name that can optionally contain a trailing slash: Bob.Smith(?'trailingSlash'\/)? - *if* the trailing slash is matched, then - and only then - optionally attempt to match a filename: (?(1)\/default\.aspx)? Giving a full pattern of: \/Directory\/Bob.Smith(?'trailingSlash'\/)?(?(1)\/default\.aspx)?
Scott decided - correctly in my opinion - to go with the excellent example provided by Wayne (as shown in Scott's blog entry). I liked the solution offered up by Wayne because of it's "free-flowing" nature. It's a trait of great minds - I believe - that they are able to come up with elegant, free-flowing solutions that work within the boundaries of the problem domain as opposed to solutions that seemingly apply more and more band-aids to stop problems entering the space of the solution. This is a skill that I aspire to in my own problem solving and, I find that it's an skill that regex constantly presents opportunities to hone - hmmmmmm, perhaps that's what actually attracts me to regex!
This thread on the regex list was interesting at several layers; firstly the quality of the explanations was high and it demonstrated the thought processes that go into constructing regex. It also highlighted the tricky nature of data - as was evidenced by the failure of Scott's initial solution when an unthought of variable was entered into the equation.