Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Glob to Regex issue

by dt667 (Acolyte)
on Nov 18, 2015 at 14:44 UTC ( #1148024=perlquestion: print w/replies, xml ) Need Help??
dt667 has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to use Text::Glob to convert various glob patterns to perl regex patterns. It appears to work fine for all but this one: \[hello\] The expected output is: (?=[^\.])\[hello\] but I am getting: (?=[^\.])[hello] Is my expected outcome wrong and the module correct? I've looked at the perl module and if I add
elsif ($_ eq '[') { $regex .= $escaping ? "\\[" : $_; } elsif ($_ eq ']') { $regex .= $escaping ? "\\]" : $_; }
at line 60, my expected result is produced. Again, is my logic flawed here?

Replies are listed 'Best First'.
Re: Glob to Regex issue
by SuicideJunkie (Vicar) on Nov 18, 2015 at 15:16 UTC

    If the text in your source file is <"\\[">, then your string becomes <\[> and your regex looks for a literal <[>

    If the text in your source file is <"\[">, then your string becomes <[> and your regex sees the start of a character class.


    OR, you can use single quotes to avoid the interpolation:

    If the text in your source file is <'\\['>, then your string becomes <\\[> and your regex looks for a literal <\[>

    If the text in your source file is <'\['>, then your string becomes <\[> and your regex looks for a literal <[>


    If you are typing it as a one-liner into the command prompt, then you'll need twice as many backslashes of course.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1148024]
Approved by Athanasius
help
Chatterbox?
[erix]: yeah. it's been some time since I last built a (linux) kernel but perl takes less than 30s and postgresql less than 2 minutes minutes :)
[talexb]: Yep .. came across SuSE 6.2 in my storage locker recently. How old is that.
[erix]: 2001 :)
[erix]: (I have the wp pages open :))

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2018-07-17 17:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (374 votes). Check out past polls.

    Notices?