|
|
|
|
|
by magicmouse
1842 days ago
|
|
Okay, i didn't know you had to put in spaces in HN comments to get it to format, here is the regular expression in classic Unix style versus Beads style for the IPv4 address (1.2.3.4): JS style:
(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]){3} Beads style: pattern octet
group or
digit // matches 0..9
set:'1-9' digit // matches 10 .. 99
'1' digit digit // matches 100 .. 199
'2' set:'0-4' digit // matches 200 .. 249
'25' set:'0-5' // matches 250 ..255
pattern IPv4
octet '.' octet '.' octet '.' octet
As you can see the Beads pattern notation allow subroutines, uses keywords like 'digit' instead of \d, and is far more readable. There are plenty of examples, and the more complex the expression the more favorable the comparison. |
|