Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Don't use a regex, use File::Spec, which is a core module (or you can use e.g. Path::Class or Path::Tiny from CPAN). use File::Spec; my $filename = File::Spec->splitpath($fullpath); - if this script is running on a non-Windows system but you need to handle Windows filenames, write File::Spec::Win32 instead of File::Spec.

Update: After rereading I realize you're also trying to extract the path from a string that looks like "TEXT: \"...\"". I feel like we might be missing some context, because the file format is unclear to me - is this some standardized file format you're trying to extract a part of? If so, what format? Usually quoted strings also have some kind of escaping mechanism, is that the case here? All of this things will affect what the best solution is. If the format really is as simple as it seems, then I would combine Corion's solution to extract the string from the quotes with my suggestion above to extract the filename.


In reply to Re: Regex to get file name from the path with spaces (updated) by haukex
in thread Regex to get file name from the path with spaces by szpt9m

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-04-20 03:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found