Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Named Captures in Regular Expressions


  • Please log in to reply
No replies to this topic

#1 NameOfTheDragon

NameOfTheDragon

    Advanced Member

  • Members
  • PipPipPip
  • 112 posts
  • LocationCanterbury, Kent, UK

Posted 06 July 2015 - 04:05 PM

Why don't named captures work in regular expressions? For example, in the following expression:

<(?<Address>(\w\d)),(?<Transaction>\d+),(?<Verb>[A-Za-z]\w+)(=((?<NumericPayload>\d+)|(?<TextPayload>.+)))?>

This should produce named captures named "Address", "Transaction", "Verb" and so on. This works in desktop applications, but in a .NetMF app it produces an error RegexpSyntaxException: Mising operand to closure.

 

Oddly, the Match class has all the members needed to retrieve matched groups, as in this code which compiles correctly:

            var deviceAddress = matches.Groups["Address"].Value;
            var transaction = int.Parse(matches.Groups["Transaction"].Value);
            var verb = matches.Groups["Verb"].Value;

So on that basis it seems odd that the regular expression parser appears to not support named captures - a great shame because it make using regular expressions much 'cleaner' and somewhat self-documenting.

 

I can't find any statements on what is and isn't supported in regular expressions in NetMF, so on the face of it this would appear to be a bug, either in the code or the documentation.

 

Any comments?

 

--Tim Long






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.