YUANya

导航

 

小骆驼 第七章 漫游正则表达式王国

#!/usr/bin/perl

use strict;
use warnings;

$_ = 'ab \  cde f ghijk10.x12ln';

if(/d/){print "get!\n";}

if(/x/){print "get!\n";}else{print "no match!\n"}

if(/\p{space}/){print "get!\n";}else{print "no match!\n"}

if(/\p{Digit}/){print "get!\n";}else{print "no match!\n"}

if(/\p{Digit}\p{Hex}/){print "get!\n";}else{print "no match!\n"}

if(/\P{Digit}\p{Hex}/){print "get!\n";}else{print "no match!\n"}

if(/g.i/){print "get!\n";}else{print "no match!\n"}

if(/\./){print "get!\n";}else{print "no match!\n"}

if(/\\/){print "get!\n";}else{print "no match!\n"}

#get!
#no match!
#get!
#get!
#get!
#get!
#get!
#get!
#get!

$_ = 'aaaabbiaaccdd1122';

if(/(..)\1/){print "$1\n";}else{print "no match!\n"}

if(/(..)\1(.)\2i\1/){print "$1,$2\n";}else{print "no match!\n"}

if(/(.)\1(.)\211/){print "$1,$2\n";}else{print "no match!\n"}

if(/(.)\1(.)\g{-1}11/){print "$1,$2\n";}else{print "no match!\n"}

if(/(.)\1(.)\g{2}11/){print "$1,$2\n";}else{print "no match!\n"}

#aa
#aa,b
#no match!
#c,d
#c,d

if(/([^ab]+)/){print "$1\n";}else{print "no match!\n"}

if(/([ab]+)/){print "$1\n";}else{print "no match!\n"}

if(/([^\d\D]+)/){print "$1\n";}else{print "no match!\n"}

#i
#aaaabb
#no match!
posted on 2019-06-16 20:36  YUANya  阅读(385)  评论(0编辑  收藏  举报