Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Regex to get file name from the path with spaces

by szpt9m (Novice)
on Sep 08, 2021 at 08:04 UTC ( [id://11136557]=note: print w/replies, xml ) Need Help??


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

Thanks for the response. I have many other lines to capture in the regex and here to make it easier i have given a part of the regex where i am facing issue. So i need a fix in the regex so that i can adapt the existing code
  • Comment on Re^2: Regex to get file name from the path with spaces

Replies are listed 'Best First'.
Re^3: Regex to get file name from the path with spaces
by Corion (Patriarch) on Sep 08, 2021 at 08:07 UTC

    Maybe you can think of your capture problem in a different way then. Most likely, you want everything after the last "path separator" up until the double quotes:

    TEXT:\s+".*?[\\/]([^\\/"]+)"

    The filename can contain everything except a path separator (\ or /) and double quotes, and must be followed by double quotes.

      Thanks This worked for me .*TEXT:\s+".*?[\\\/]([^\\\/"]+)"
      somehow it is not working for me or am i doing something wrong :( used it like this  .*TEXT:\s+".*?[\/]([\/"]+)" as \\ was not recognized and for my input TEXT: "C:\temp\test äbc.txt" there were no matches found
        You're missing the negation ^ in the character class. Also, you're using forward slashes in the regex, but backslashes in the string. Moreover, I'm not sure the ? is needed.
        #! /usr/bin/perl use strict; use warnings; use utf8; my $input = 'TEXT: "C:\temp\test äbc.txt"'; print $input =~ /.*TEXT:\s+".*[\\]([^\\"]+)"/; # ~ ~ ~ ~
        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11136557]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found