Thread overview
tango -D2 regex
Dec 16, 2013
seany
Dec 16, 2013
evilrat
Dec 16, 2013
seany
Dec 16, 2013
Dmitry Olshansky
Dec 16, 2013
JR
Dec 16, 2013
Dmitry Olshansky
Dec 17, 2013
seany
Dec 16, 2013
John Colvin
December 16, 2013
I dont find any info on backtrack on tango-D2 regex.

For example, I want to match things like

barFOObar

or

bazFOObaz

so I would use, in PCRE, ^(\w*)FOO($1)$, with $1 meaning the word (given by \w*  that was matced in the first subpattern (\w*)

How to do the samein Tango for D2 (or even phobos for D2)?
December 16, 2013
On Monday, 16 December 2013 at 07:46:30 UTC, seany wrote:
> I dont find any info on backtrack on tango-D2 regex.
>
> For example, I want to match things like
>
> barFOObar
>
> or
>
> bazFOObaz
>
> so I would use, in PCRE, ^(\w*)FOO($1)$, with $1 meaning the word (given by \w*  that was matced in the first subpattern (\w*)
>
> How to do the samein Tango for D2 (or even phobos for D2)?

have you tried look the docs first?

phobos regex patterns described here
http://dlang.org/phobos/std_regex.html

December 16, 2013
On Monday, 16 December 2013 at 07:56:53 UTC, evilrat wrote:

>
> have you tried look the docs first?
>
> phobos regex patterns described here
> http://dlang.org/phobos/std_regex.html

The only mention of backtrack is : bmatch
it returns a regex object with a machine state, and last match, but it is still not telling me how to actually do a backtrack match. I.e. if i know the machine state and a match (in my example, does that mean that foo is returned as a match or does it mean thatbaz /bar is returned as a match, and the next attempt will match the bar/baz - if not, then what is the call sequence? bmatch (match bar/baz) then match FOO, then again try to match what bmatch returned?)

December 16, 2013
On Monday, 16 December 2013 at 07:46:30 UTC, seany wrote:
> I dont find any info on backtrack on tango-D2 regex.
>
> For example, I want to match things like
>
> barFOObar
>
> or
>
> bazFOObaz
>
> so I would use, in PCRE, ^(\w*)FOO($1)$, with $1 meaning the word (given by \w*  that was matced in the first subpattern (\w*)
>
> How to do the samein Tango for D2 (or even phobos for D2)?

Something like http://dpaste.dzfl.pl/0e02c3d1 ? Phobos though.

December 16, 2013
16-Dec-2013 11:46, seany пишет:
> I dont find any info on backtrack on tango-D2 regex.
>
> For example, I want to match things like
>
> barFOObar
>
> or
>
> bazFOObaz
>
> so I would use, in PCRE, ^(\w*)FOO($1)$, with $1 meaning the word (given
> by \w*  that was matced in the first subpattern (\w*)

With std.regex of Phobos this should just work.

auto re = regex(`^(\w*)FOO\1$`);

assert("barFOObar".match(re));

Syntax is like in JavaScript or Perl.

>
> How to do the samein Tango for D2 (or even phobos for D2)?


-- 
Dmitry Olshansky
December 16, 2013
16-Dec-2013 12:06, seany пишет:
> On Monday, 16 December 2013 at 07:56:53 UTC, evilrat wrote:
>
>>
>> have you tried look the docs first?
>>
>> phobos regex patterns described here
>> http://dlang.org/phobos/std_regex.html
>
> The only mention of backtrack is : bmatch
> it returns a regex object with a machine state, and last match, but it
> is still not telling me how to actually do a backtrack match.

Docs don't state anything like that. It finds _first_ match and returns full state so that you may continue matching or just look at the current match.

Backtracking is purely irrelevant technical detail.

> I.e. if i
> know the machine state and a match (in my example, does that mean that
> foo is returned as a match or does it mean thatbaz /bar is returned as a
> match, and the next attempt will match the bar/baz - if not, then what
> is the call sequence? bmatch (match bar/baz) then match FOO, then again
> try to match what bmatch returned?)

Simply put match/bmatch will return a range of matches as they are found in the input. Each match is, in turn, a random access range that contains full match, followed by each sub-match in the pattern.

-- 
Dmitry Olshansky
December 16, 2013
On Monday, 16 December 2013 at 07:46:30 UTC, seany wrote:
> I dont find any info on backtrack on tango-D2 regex.
>
> For example, I want to match things like
>
> barFOObar
>
> or
>
> bazFOObaz
>
> so I would use, in PCRE, ^(\w*)FOO($1)$, with $1 meaning the word (given by \w*  that was matced in the first subpattern (\w*)
>
> How to do the samein Tango for D2 (or even phobos for D2)?

FYI if you know your regex at compile-time, the ctRegex in phobos is *very* fast.
December 17, 2013
On Monday, 16 December 2013 at 17:20:59 UTC, Dmitry Olshansky wrote:
> 16-Dec-2013 11:46, seany пишет:
>> I dont find any info on backtrack on tango-D2 regex.
>>
>> For example, I want to match things like
>>
>> barFOObar
>>
>> or
>>
>> bazFOObaz
>>
>> so I would use, in PCRE, ^(\w*)FOO($1)$, with $1 meaning the word (given
>> by \w*  that was matced in the first subpattern (\w*)
>
> With std.regex of Phobos this should just work.
>
> auto re = regex(`^(\w*)FOO\1$`);
>
> assert("barFOObar".match(re));
>
> Syntax is like in JavaScript or Perl.
>
>>
>> How to do the samein Tango for D2 (or even phobos for D2)?

thanks! this is what i was looking for (the \1)