Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Defining your own regex character class

by haukex (Abbot)
on Dec 18, 2017 at 08:26 UTC ( #1205776=note: print w/replies, xml ) Need Help??

in reply to Defining your own regex character class

There is an experimental feature (that I haven't used yet), Extended Bracketed Character Classes, that should allow you to define your own classes (or more specifically, compose a character class out of others, which you can also interpolate into a regex).

However, /\b(?:[[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}\b/ is not a character class (emphasis mine):

A character class is a way of denoting a set of characters in such a way that one character of the set is matched. It's important to remember that: matching a character class consumes exactly one character in the source string.

What you've got is a whole regex, and I think that LanX is right that simply compiling that into a variable with qr and interpolating that into another regex is the best way to go. Later in that thread you asked if you could isolate the variable, and the usual ${} can be applied here too, as well as the /x modifier:

my $x = qr/foo/; my $y = qr/${x}bar/; # (?^:(?^:foo)bar) my $z = qr/ $x bar /x; # (?^x: (?^:foo) bar )

Regarding the example you've shown, note there is $RE{net}{IPv4} from Regexp::Common::net.

Minor edits for clarification.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1205776]
and all is quiet...

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

    Results (469 votes). Check out past polls.