This updated version need a Unicode::UCD with prop_invlist, which started with perl 5.016

See perlunicode, perluniprops, perlrecharclass, Unicode::UCD, Data::Dump, List::MoreUtils

#!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd pp /; use List::MoreUtils qw' uniq '; use Unicode::UCD qw/ prop_invlist /; Main( @ARGV ); exit( 0 ); sub uRanges { RangeIt( shift, '\\u%04.4X' ) } sub pRanges { RangeIt( shift, '\\N{U+%04.4X}' ) } sub iRanges { RangeIt( shift, '%04.4X', '%04.4X %04.4X' ) } sub RangeIt { my( $punct , $format1, $format2 ) = @_; $format1 ||= '\\N{U+%04.4X}'; $format2 ||= join '-', $format1, $format1; my @invlist = prop_invlist( $punct ); unless( @invlist ){ warn "## empty for $punct \n"; return; } my @ranges; for (my $i = 0; $i < @invlist; $i += 2) { my $lower = $invlist[ $i ]; my $upper = ($i + 1) < @invlist ? $invlist[$i+1] - 1 # In range : $Unicode::UCD::MAX_CP; # To infinity. You may +want # to stop much much earl +ier; # going this high may ex +pose # perl deficiencies with + very # large numbers. if( $lower != $upper ){ push @ranges, sprintf $format2, $lower, $upper; } else { push @ranges, sprintf $format1, $lower; } } @ranges; } sub Main { use Getopt::Long qw/ GetOptionsFromArray /; my %opt; GetOptionsFromArray( \@_, \%opt, q{i|is|in!}, q{p|perl!}, q{j|js|java|javascript!}, q{u|utf!}, q{h|help!}, ); $opt{h} and return Usage(); @_ or return Usage(); my %rangers = ( j => sub { printf "%s => %s\n\n", $_[0], join '', uRanges( $_ +[0] ); }, p => sub { printf "%s => %s\n\n", $_[0], join '', pRanges( $_ +[0] ); }, i => sub { print qq{sub Is$_[0] { return <<'$_[0]';\n@{[ join + "\n", iRanges( $_[0] ) ]}\n$_[0]\n} ## end of Is$_[0]\n\n}; }, u => sub { print qq{sub Is$_[0] { return <<'$_[0]';\n+utf8::$ +_[0]\n$_[0]\n} ## end of Is$_[0]\n\n}; }, ); $rangers{''} ||= $rangers{j} ; my $ranger = $rangers{ ( keys %opt )[0] || '' };## ick for my $k ( uniq @_ ){ $ranger->( $k ); } } sub Usage { print "\nUsage:\n $0 [ -i -j -u -p ] Punctuation\n"; print "\n $0 PerlSpace Title Bopo Dingbats AHex \n"; #~ print "\n $0 ASCII_Hex_Digit=Yes ASCII_Hex_Digit=No \n"; print q{ $ perl unicharproptoregexrange.pl Dingbats Dingbats => \u2700-\u27BF $ perl unicharproptoregexrange.pl -j Dingbats Dingbats => \u2700-\u27BF $ perl unicharproptoregexrange.pl -p Dingbats Dingbats => \N{U+2700}-\N{U+27BF} $ perl unicharproptoregexrange.pl -i Dingbats sub IsDingbats { return <<'Dingbats'; 2700 27BF Dingbats } ## end of IsDingbats $ perl unicharproptoregexrange.pl -u Dingbats sub IsDingbats { return <<'Dingbats'; +utf8::Dingbats Dingbats } ## end of IsDingbats See perldoc perluniprops };;;;;;; } __END__

In reply to Re: expand unicode property (eg \p{Print}) to regex character class range (unicharproptoregexrange.pl) by Anonymous Monk
in thread expand unicode property (eg \p{Print}) to regex character class range by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.