emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Make regexp handling more regular


From: Vasilij Schneidermann
Subject: Re: Make regexp handling more regular
Date: Thu, 3 Dec 2020 23:20:30 +0100

> Notably in Ruby e.g. /(.)(.)(.)/.match("foo") returns a MatchData object:
> 
>   #<MatchData "foo" 1:"f" 2:"o" 3:"o">
> 
> Shouldn't a function like string-match (or rather some new function)
> return a #<MatchData> object too?  Or the current list returned
> by the function 'match-data' is sufficient?

Personally I find the pattern of mixing a check for a match object, then
access to the global match variables a lot more convenient in Ruby than
extracting the data from the match object:

    'foo123bar'[/[a-z]+([0-9]+)[a-z]+/] && $1 #=> "123"

The alternative:

    m = /[a-z]+([0-9]+)[a-z]+/.match('foo123bar')
    m && m[1] #=> "123"

The above is more attractive if there was an if-let/when-let
equivalent. So that's what I'd design against.

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]