Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: regex is not working as I intended

by fireblood (Acolyte)
on Jan 22, 2018 at 19:11 UTC ( #1207700=note: print w/replies, xml ) Need Help??


in reply to Re^2: regex is not working as I intended
in thread regex is not working as I intended

I forgot to mention that this regex is used repeatedly on the same string to parse out parameter and value pairs, such as the following:

radius = 3, density = .014, URL = "https://www.geometry.org", max_no_of_attempts = 4

That is why the lookbehind and lookahead assertions are used, even though they cannot possibly match at the beginning or end of the overall parameter string, they can match at intermediate positions as the regex is used to walk over the value of the parameter string parsing out individual parm and value pairs.

Replies are listed 'Best First'.
Re^4: regex is not working as I intended
by AnomalousMonk (Bishop) on Jan 23, 2018 at 01:05 UTC

    Further to GrandFather's post:   Part of the useful enhanced context would be an expected hash structure for each multiple parameter/value pair string (hopefully, more than just one!) that you provide. E.g., for the multi-line string example here, do you expect

    %values = ( 'radius' => 3, 'density' => .014, 'URL' => '"https://www.geometry.org"', 'max_no_of_attempts' => 4, );
    or do you want something like
    %values = ( ..., 'URL' => 'https://www.geometry.org', ..., );
    (double-quotes stripped away)? How should wonky quoted strings be handled? By die-ing. By warn-ing and continuing to process? In another way?

    And yes, I think a module probably already exists to do this sort of thing.


    Give a man a fish:  <%-{-{-{-<

Re^4: regex is not working as I intended
by GrandFather (Sage) on Jan 22, 2018 at 22:38 UTC

    Maybe you should create a new node with a bit more of the context for this problem. It sounds to me like there could be a call for a bigger hammer than just a single regex.

    Premature optimization is the root of all job security
Re^4: regex is not working as I intended
by ikegami (Pope) on Jan 22, 2018 at 23:15 UTC

    That doesn't change anything. The fixed version provided by Grandfather can be used to in parsing the snippet you provided.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2020-04-07 20:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The most amusing oxymoron is:
















    Results (43 votes). Check out past polls.

    Notices?