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

Re: Looking for a cleaner regex

by QM (Parson)
on Dec 08, 2017 at 14:38 UTC ( #1205173=note: print w/replies, xml ) Need Help??


in reply to Looking for a cleaner regex

See Regexp::Optimizer

-QM
--
Quantum Mechanics: The dreams stuff is made of

Replies are listed 'Best First'.
Re^2: Looking for a cleaner regex ( trie since 5.10 ! )
by LanX (Cardinal) on Dec 08, 2017 at 14:45 UTC
      making the regex shorter and easier to read?
        Do you really find /foo(?:[bx]ar|zap)/ easier to read than /foobar|fooxar|foozap/? (Example copied from the documentation).

        Or,

        /(?^:(?^x:(?:s(?:e(?:t(?:(?:(?:(?:hos|ne)t|gr)en|s(?:erven|ockop))t|p( +?:r(?:iority|otoent)|went|grp))|m(?:ctl|get|op)|ek(?:dir)?|lect|nd)|y +(?:s(?:write|call|open|read|seek|tem)|mlink)|h(?:m(?:write|read|ctl|g +et)|utdown)|ocket(?:pair)?|(?:qr|ta)t|printf|ubstr|leep|rand|in)|g(?: +e(?:t(?:p(?:r(?:oto(?:byn(?:umber|ame)|ent)|iority)|w(?:ent|nam|uid)| +eername|grp|pid)|s(?:erv(?:by(?:name|port)|ent)|ock(?:name|opt))|host +(?:by(?:addr|name)|ent)|net(?:by(?:addr|name)|ent)|gr(?:ent|gid|nam)| +login|c))?|mtime|lob|t)|r(?:e(?:ad(?:lin[ek]|pipe|dir)?|(?:quir|vers| +nam)e|winddir|set|cv|f)|index|mdir|and)|c(?:h(?:r(?:oot)?|dir|mod|own +)|o(?:n(?:tinue|nect)|s)|lose(?:dir)?|aller|rypt|mp)|l(?:o(?:c(?:alti +me|k)|g)|i(?:sten|nk)|c(?:first)?|e(?:ngth)?|(?:sta)?t)|e(?:nd(?:(?:h +os|ne)t|p(?:roto|w)|serv|gr)ent|x(?:ec|it|p)|of|q)|u(?:(?:n(?:lin|pac +)|mas)k|c(?:first)?|time)|f(?:or(?:mline|k)|c(?:ntl)?|ileno|lock)|w(? +:a(?:it(?:pid)?|ntarray|rn)|rite)|m(?:sg(?:ctl|get|rcv|snd)|kdir)|t(? +:ell(?:dir)?|runcate|imes?)|d(?:bm(?:close|open)|ump|ie)|a(?:ccept|la +rm|tan2|bs|nd)|__(?:(?:FIL|LIN)E|SUB)__|o(?:pen(?:dir)?|rd?|ct)|b(?:i +n(?:mode|d)|less)|i(?:n(?:dex|t)|octl)|v(?:alues|ec)|p(?:ack|ipe)|n(? +:ot|e)|quotemeta|x(?:or)?|CORE|join|kill|hex)))/

        versus

        /CORE|__FILE__|__LINE__|__SUB__|abs|accept|alarm|and|atan2|bind|binmod +e| bless|caller|chdir|chmod|chown|chr|chroot|close|closedir|cmp|connect| continue|cos|crypt|dbmclose|dbmopen|die|dump|endgrent|endhostent|endne +tent| endprotoent|endpwent|endservent|eof|eq|exec|exit|exp|fc|fcntl|fileno|f +lock| fork|formline|ge|getc|getgrent|getgrgid|getgrnam|gethostbyaddr| gethostbyname|gethostent|getlogin|getnetbyaddr|getnetbyname|getnetent| getpeername|getpgrp|getppid|getpriority|getprotobyname|getprotobynumbe +r| getprotoent|getpwent|getpwnam|getpwuid|getservbyname|getservbyport| getservent|getsockname|getsockopt|glob|gmtime|gt|hex|index|int|ioctl|j +oin| kill|lc|lcfirst|le|length|link|listen|localtime|lock|log|lstat|lt|mkdi +r| msgctl|msgget|msgrcv|msgsnd|ne|not|oct|open|opendir|or|ord|pack|pipe| quotemeta|rand|read|readdir|readline|readlink|readpipe|recv|ref|rename +| require|reset|reverse|rewinddir|rindex|rmdir|seek|seekdir|select|semct +l| semget|semop|send|setgrent|sethostent|setnetent|setpgrp|setpriority| setprotoent|setpwent|setservent|setsockopt|shmctl|shmget|shmread|shmwr +ite| shutdown|sin|sleep|socket|socketpair|sprintf|sqrt|srand|stat|substr| symlink|syscall|sysopen|sysread|sysseek|system|syswrite|tell|telldir|t +ime| times|truncate|uc|ucfirst|umask|unlink|unpack|utime|values|vec|wait| waitpid|wantarray|warn|write|x|xor/x

        ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      It isnt limited by trie max limit maybe?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2021-04-16 02:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?