GNU bug report logs -
#30568
27.0.50; `rx' doesn't create optimal regex for (group (or ...))
Previous Next
Full log
View this message in rfc822 format
> (rx (group (or "aaa" "bbb")))
> ==> \(\(?:aaa\|bbb\)\)
>
> This should generate \(aaa\|bbb\) instead. Of course, these regexes are
> equivalent, but the second one is easier to read (and maybe faster).
This remains unchanged, I'm afraid, despite rx being completely rewritten. Not that it matters much: brackets do not generate any regexp bytecode, thus matching performance isn't affected once the regexp has been compiled. When the brackets are required, there is no waste:
(rx (+ (or "aaa" "bbb")))
=> "\\(?:aaa\\|bbb\\)+"
Still, it's a bit untidy, and I like that you reported it. We could add a special value for the PAREN argument to regexp-opt to prevent bracketing altogether, I suppose. It isn't immediately on my to-do list, however.
This bug report was last modified 5 years and 185 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.