regex problems

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Sep 20 11:49:43 PDT 2014


On Saturday, 20 September 2014 at 15:28:54 UTC, seany wrote:
> In haystack, there are two such "ID :" -s. once at the 
> beginning, ID : generateWorld. and then the final, last ID
>
> However, this is returning all 5 ID-s as match
>
> what am I doing wrong?

Prints

ID :
ID :

for me.

I'd advise against using regular expressions in this way, though.
They are not the proper tool for nested structures. Coming up
with correct(!) regexes is probably harder than the alternatives:
* using a parser generator like Pegged [1] (haven't used it
myself) which supports more powerful grammars than regular
expressions,
* writing a (recursive descent) parser manually.

[1] https://github.com/PhilippeSigaud/Pegged


More information about the Digitalmars-d-learn mailing list