Live data from Hacker News

Sat solver on top of regex matcher

yurichev.com

1–10 of 53 posts

Re: Sat solver on top of regex matcher

#4
post #3

> Another practical usage I've heard: match "string" or 'string', but not "string'. You don't need backreferences for that: '[^']*'|"[^"]*"

Won't work if you're already in a string, or if there are escaped quotes in the string. Also won't work if you have two or more double quoted strings that both contain an apostrophe.

Re: Sat solver on top of regex matcher

#5
post #2

This reduction is really cool. I love reductions like this. Is there a general consensus to use "regular expression" to refer to the actual regular ones and "regex" to refer to the non-regular variants?

I don't think so. Usually you can tell from the context:

# math and/or computer science texts? It's the regular ones.

# pretty much elsewhere? It's the extended ones.

# threads about parsing HTML with regular expressions? People using both and insisting their version is the only correct one.

Re: Sat solver on top of regex matcher

#6
post #3

> Another practical usage I've heard: match "string" or 'string', but not "string'. You don't need backreferences for that: '[^']*'|"[^"]*"

Won't work if you're already in a string, or if there are escaped quotes in the string. Also won't work if you have two or more double quoted strings that both contain an apostrophe.

Escaping isn't an intrinsic property of all quoted strings (e.g. single quoted strings in bash), but even so one can work around them without backreferences, by searching for anything that's not a quote or a backslash, _or_ any escaped character:

    /"([^"\\]|\\.)*"/
Now double that up with a single quote version if you wish.

What you can't match without backreferences, however, is strings with customisable terminators, e.g. the behaviour in sed that whatever character you use after `s` is the regex terminator (it doesn't have to be `/`), or raw strings in C++.

Re: Sat solver on top of regex matcher

#7
post #3

> Another practical usage I've heard: match "string" or 'string', but not "string'. You don't need backreferences for that: '[^']*'|"[^"]*"

Won't work if you're already in a string, or if there are escaped quotes in the string. Also won't work if you have two or more double quoted strings that both contain an apostrophe.

Backreferences don't really help with those problems.

> Won't work if you're already in a string

This doesn't make sense. How can you search for a string if you're already in a string? I can't think of a realistic situation where that would be useful or even really possible.

> or if there are escaped quotes in the string.

Solvable:

    '(\'|\\|[^\'])*'|"(\"|\\|[^\"])*"
> Also won't work if you have two or more double quoted strings that both contain an apostrophe.

The regex in my previous comment already solves that. See: https://repl.it/repls/SolidCapitalProgram

Re: Sat solver on top of regex matcher

#9
post #2

This reduction is really cool. I love reductions like this. Is there a general consensus to use "regular expression" to refer to the actual regular ones and "regex" to refer to the non-regular variants?

I think Raku (neé Perl 6) has been spearheading that distinction

https://docs.raku.org/language/regexes (see the intro paragraph)

Re: Sat solver on top of regex matcher

#10
post #2

This reduction is really cool. I love reductions like this. Is there a general consensus to use "regular expression" to refer to the actual regular ones and "regex" to refer to the non-regular variants?

I wouldn't say so, but I use the term "regular language" if I mean the mathematical concept.
Post reply on HN