www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - tango -D2 regex

reply "seany" <seany uni-bonn.de> writes:
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)?
Dec 15 2013
next sibling parent reply "evilrat" <evilrat666 gmail.com> writes:
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
Dec 15 2013
parent reply "seany" <seany uni-bonn.de> writes:
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?)
Dec 16 2013
parent Dmitry Olshansky <dmitry.olsh gmail.com> writes:
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
Dec 16 2013
prev sibling next sibling parent "JR" <zorael gmail.com> writes:
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.
Dec 16 2013
prev sibling next sibling parent reply Dmitry Olshansky <dmitry.olsh gmail.com> writes:
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
Dec 16 2013
parent "seany" <seany uni-bonn.de> writes:
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)
Dec 17 2013
prev sibling parent "John Colvin" <john.loughran.colvin gmail.com> writes:
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.
Dec 16 2013