Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Complex regex question

by tybalt89 (Monsignor)
on Sep 25, 2019 at 14:16 UTC ( [id://11106680]=note: print w/replies, xml ) Need Help??


in reply to Complex regex question

Maybe not the best solution :)

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11106665 use warnings; my $string_three = 'foo bar [21a] plus (b23) baz bax'; my @string_three_results = $string_three =~ m{ ( [ab] | \d+ ) ( (??{$1 lt 'a' ? '[ab]' : '\\d+' }) ) }gx; use Data::Dump 'dd'; dd \@string_three_results;

Outputs:

[21, "a", "b", 23]

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2024-03-28 11:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found