From: Kashyap Chamarthy <kchamart@redhat.com>
To: John Snow <jsnow@redhat.com>
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>,
qemu-devel@nongnu.org, armbru@redhat.com,
"Cleber Rosa" <crosa@redhat.com>,
ehabkost@redhat.com
Subject: Re: [Qemu-devel] [PATCH] qmp-shell: fix nested json regression
Date: Wed, 6 Feb 2019 12:09:47 +0100 [thread overview]
Message-ID: <20190206110947.GU5349@paraplu.home> (raw)
In-Reply-To: <20190206104851.GT5349@paraplu.home>
On Wed, Feb 06, 2019 at 11:48:51AM +0100, Kashyap Chamarthy wrote:
> On Tue, Feb 05, 2019 at 08:44:12PM -0500, John Snow wrote:
> > On 2/5/19 8:49 AM, Marc-André Lureau wrote:
[...]
> > > < command-name > [ arg-name1=arg1 ] ... [ arg-nameN=argN ]
> > > """
> > > - cmdargs = shlex.split(cmdline)
> > > + cmdargs = re.findall(r'''(?:[^\s"']|"(?:\\.|[^"])*"|'(?:\\.|[^'])*')+''', cmdline)
Dan Berrangé explained on IRC this way:
In plain english what that is saying is: give me all blocks of text
which are:
(a) set of chars not including " or '
(b) a set of chars surrounded by ".."
(c) a set of chars surrounded by '...
> > It might really be nice to have a comment briefly explaining the regex.
> > This is pretty close to symbol soup.
>
> Yeah, a little comment explaining it would be nice.
For my own education today I learned that ?: is called a "non-capturing
match". For reference, quoting from the `perldoc perlretut`:
[quote]
Non-capturing groupings
A group that is required to bundle a set of alternatives may or may not
be useful as a capturing group. If it isn't, it just creates a
superfluous addition to the set of available capture group values,
inside as well as outside the regexp. Non-capturing groupings, denoted
by "(?:regexp)", still allow the regexp to be treated as a single unit,
but don't establish a capturing group at the same time. Both capturing
and non-capturing groupings are allowed to co-exist in the same regexp.
Because there is no extraction, non-capturing groupings are faster than
capturing groupings. Non-capturing groupings are also handy for choosing
exactly which parts of a regexp are to be extracted to matching
variables:
# match a number, $1-$4 are set, but we only want $1
/([+-]?\ *(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?)/;
# match a number faster , only $1 is set
/([+-]?\ *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?)/;
# match a number, get $1 = whole number, $2 = exponent
/([+-]?\ *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE]([+-]?\d+))?)/;
Non-capturing groupings are also useful for removing nuisance elements
gathered from a split operation where parentheses are required for some
reason:
$x = '12aba34ba5';
@num = split /(a|b)+/, $x; # @num = ('12','a','34','a','5')
@num = split /(?:a|b)+/, $x; # @num = ('12','34','5')
[/quote]
[...]
--
/kashyap
next prev parent reply other threads:[~2019-02-06 11:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-05 13:49 [Qemu-devel] [PATCH] qmp-shell: fix nested json regression Marc-André Lureau
2019-02-06 1:44 ` John Snow
2019-02-06 10:48 ` Kashyap Chamarthy
2019-02-06 11:09 ` Kashyap Chamarthy [this message]
2019-03-08 22:50 ` John Snow
2019-03-09 9:01 ` Markus Armbruster
2019-03-11 13:27 ` Eduardo Habkost
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190206110947.GU5349@paraplu.home \
--to=kchamart@redhat.com \
--cc=armbru@redhat.com \
--cc=crosa@redhat.com \
--cc=ehabkost@redhat.com \
--cc=jsnow@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).