Orginally we were parsing xml files that had the following href attribute values:
href="file.txt"
Now the href attributes can have a relative path:
href=".../docs/file.txt"
In either case I need to return just the file name. We had the following python code calling the following regular expression:
href_pattern = r'href="([^"]*)
While this worked only the filename was there, with a relative path, it will return that as well.
I know that a regular expression of the form:
([^\/]*$)
Will pull the filename only if a relative path is in the value.
My question, as I'm not a regular expression expert, is what is a regular expression that would work in both cases?
Thanks for any help or pointers!
Russ
It doesn't exactly answer the question but I suggest you to extract the field as you did in the previous version and then you can extract the filename from that result.
Regular Expression to return filename and extension if there is a realtive path or not