Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: RegEx for users who dont know RegEx

by ikegami (Pope)
on Dec 23, 2004 at 17:23 UTC ( #417159=note: print w/replies, xml ) Need Help??


in reply to RegEx for users who dont know RegEx

Something like this?

($reg_exp = $user_query) =~ s/(\W)/$1 eq '*' ? "\\S*" : "\\$1"/ge;

It can be used as follows:

# File as an array of lines: @matching_lines = grep { /$reg_exp/ } @lines_to_search;

or

# File in a scalar: @matching_lines = $file =~ /^(.*${reg_exp}.*)$/mg;

Replies are listed 'Best First'.
Re^2: RegEx for users who dont know RegEx
by The Mad Hatter (Priest) on Dec 23, 2004 at 17:36 UTC
    ($reg_exp = $user_query) =~ s/(\W)/$1 eq '*' ? "\\S*" : "\\\$1"/ge;
    You have too many slashes in the second part of that ternary (results in invalid chars being replaced by a literal '\$1').
      Thanks. Fixed. Tested.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2018-09-24 05:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Eventually, "covfefe" will come to mean:













    Results (191 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!