Live data from Hacker News

Sat solver on top of regex matcher

yurichev.com

11–20 of 53 posts

Re: Sat solver on top of regex matcher

#11
post #3

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

The common case of only two pairs of quotes is indeed regular, but if you want to support either all Unicode quotes (about 60 pairs of them) or C++11 raw string literals `R"delim(...)delim"` (intrinsically not regular) you are out of luck.

Re: Sat solver on top of regex matcher

#12
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?

This distinction was introduced by Jeffrey Friedl’s book _Mastering Regular Expressions_ (2006), and it seems to be fairly commonly used now.

Re: Sat solver on top of regex matcher

#13
post #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.

I don’t think it’s pedantic to say that a regular language is not the same thing as a regular expression. The difference between syntax and semantics is real and important.

Re: Sat solver on top of regex matcher

#14
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.

That wasn’t specified in the requirements

Re: Sat solver on top of regex matcher

#15
post #7

Earlier quoted context omitted.

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 quo…

> 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.

    query = "select * from table where name like \"%foo\""

Re: Sat solver on top of regex matcher

#16
One of the cool features of SAT problems is that they always terminate (if you're patient enough). Aren't regex, especially with backreferences, Turing-complete though? If so, they could be caught in an infinite loop, meaning they are more general than the SAT problem.

Re: Sat solver on top of regex matcher

#18
post #16

One of the cool features of SAT problems is that they always terminate (if you're patient enough). Aren't regex, especially with backreferences, Turing-complete though? If so, they could be caught in an infinite loop, meaning they are more general than the SAT problem.

Programming languages are more general than the problems they solve. (= feature, not bug)

Still, yes, you can mess up your "add 1 to the input" program and make it run infinitely.

Re: Sat solver on top of regex matcher

#20
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?

Isn't it PCRE that we started to call it regex?
Post reply on HN