yamlscript icon indicating copy to clipboard operation
yamlscript copied to clipboard

Alternate regex syntax

Open ingydotnet opened this issue 11 months ago • 1 comments

We have /^.*\/foo\/bar.*$/ now which leads to leaning toothpick syndrome.

Clojure uses #"^.*/foo/bar.*$".

We can't use that because it would be a yaml comment a most of the time.

We can use \#"^.*/foo/bar.*$" though.

We could also use \"^.*/foo/bar.*$".

Python has ``r"^./foo/bar.$"so we could use\r"^./foo/bar.$"`.

I like \r"..." because we could later make other kinds of strings with other letters.

ingydotnet avatar Mar 11 '24 00:03 ingydotnet

Yes, I also like \r"..."

xanni avatar Mar 11 '24 00:03 xanni

A bit off-topic because it's not YAML-related, but I -- also thinking of toothpick syndrome -- recently did a ranking of possible characters for an alternate (second) regex delimiter for GitHub search. (Btw, did you know you can use regex in GitHub search? It's neat!). https://github.com/orgs/community/discussions/114708

Since people who know about toothpick syndrome and care enough about it to write posts about it, are possibly few and far between, I thought I'd risk a little off-topicness to say hi here anyway!

mevanlc avatar Jun 20 '24 23:06 mevanlc

@mevanlc Hi!

We resolved this quite nicely with rx('^.*/.*\.yaml$'). Where rx is a stand library function we just added. Also there already was one that did the same thing called re-pattern. Both generate a regex pattern object from a string.

ingydotnet avatar Jun 23 '24 02:06 ingydotnet

@ingydotnet That's a nice, brief syntax! Thanks for sharing -- I will be trying it out. How would an internal literal ' be escaped in this case? Or would you need to use an alternate quoting scheme for that (ala bash)?

mevanlc avatar Jun 24 '24 04:06 mevanlc

@mevanlc (msg =~ rx('escaping single quotes shouldn''t be a problem')) :)

YAML uses '' to escape single quotes in single quoted strings. The beauty of that choice is that there is only only character to escape. (\' would require \\).

YS does the same thing at the expression level.

ingydotnet avatar Jun 24 '24 13:06 ingydotnet