I was thinking about using the scheme pregexp library to get Perl regular expressions in arc. I am trying to find a nice syntax that would be both short and coherent. Here is what I came up with so far, which basically involves considering regexps as functions : arc> (/ca/ "bobcat")
("ca")
arc> (/(\w{1})/g "bobcat")
("b" "b" "o" "b" "c" "a" "t")
arc> (/cd/ "bobcat")
()
arc> (s/b/d/ "bobcat")
"dodcat"
arc> (s/b(\w)/d\\1/g "bobcat")
"dodcat"
I don't really like this last one, since it would have been nice to also get the list of matches, but returning a list would make it inconsistent with the one above. Returning a list for both cases would be a pain. This is probably one case where returning multiple values would be nice, arc> (= re /ob/)
/ob/
arc> (re "bobcat")
("ob")
arc> (= c 2)
2
arc> (makere "/^\d{" c "}/g")
/^\d{2}/g
What do you think ?Also, how much sense do you think it would make to have regexps as part of the core language ? I'd love to see a real discussion on regular expressions, their usefulness and possible alternatives. |