Regex 'Absent Operator'

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Regex 'Absent Operator'

Scott Morgan
Apparently Ruby's new release has added a new 'absent operator' to it's
regex engine.

https://medium.com/rubyinside/the-new-absent-operator-in-ruby-s-regular-expressions-7c3ef6cd0b99

Based on some academic paper (linked in article, but in Japanese), it's
supposed to help in certain cases matching things that are awkward or
impossible without (C style comments '/* ... */' is one example[0]).
It's a bit subtle in it's behaviour and uses.

Worth considering for Lua's pattern match system?

Scott

[0] That is '/* okay */' but avoiding '/* wrong */ */'

Reply | Threaded
Open this post in threaded view
|

Re: Regex 'Absent Operator'

Ulrich Schmidt


Am 27.03.2017 um 12:25 schrieb Scott Morgan:

> Apparently Ruby's new release has added a new 'absent operator' to it's
> regex engine.
>
> https://medium.com/rubyinside/the-new-absent-operator-in-ruby-s-regular-expressions-7c3ef6cd0b99
>
> Based on some academic paper (linked in article, but in Japanese), it's
> supposed to help in certain cases matching things that are awkward or
> impossible without (C style comments '/* ... */' is one example[0]).
> It's a bit subtle in it's behaviour and uses.
>
> Worth considering for Lua's pattern match system?
>
> Scott
>
> [0] That is '/* okay */' but avoiding '/* wrong */ */'
>

For all that pattern matching stuff we can use lpeg. Why implement some
new regex features that bloat the lua library?

u.s.

Reply | Threaded
Open this post in threaded view
|

Re: Regex 'Absent Operator'

Pierre-Yves Gérardy
In reply to this post by Scott Morgan
On Mon, Mar 27, 2017 at 12:25 PM, Scott Morgan <[hidden email]> wrote:

> [0] That is '/* okay */' but avoiding '/* wrong */ */'

using Regexes, you can either use non-greedy repetition

    /\/\*.*?\*\//

or negative lookahead in a non-capturing group:

    /\/\*(?:(?!\*\/).)*\*\//

(Assuming that /./ matches every character including new lines)

Both will match "/* wrong */"

> Worth considering for Lua's pattern match system?

I don't think so. Operators in Lua patterns only apply to the last
character or character set, and you can already use [^...] for that
purpose.