Regex question

2012-03-28 Thread James Blewitt
I'm having a problem with regexes. The following code gives a compilation error. If I comment out the regex outside of main and comment in the regex inside of main then it does compile. I'm using DMD v2.058 Any ideas what is going on? -- import std.regex; Regex!(char) testRegex = rege

Re: Regex question

2012-03-28 Thread simendsjo
On Wed, 28 Mar 2012 11:40:21 +0200, James Blewitt wrote: I'm having a problem with regexes. The following code gives a compilation error. If I comment out the regex outside of main and comment in the regex inside of main then it does compile. I'm using DMD v2.058 Any ideas what is going

Re: Regex question

2012-03-28 Thread Dmitry Olshansky
On 28.03.2012 13:40, James Blewitt wrote: I'm having a problem with regexes. The following code gives a compilation error. If I comment out the regex outside of main and comment in the regex inside of main then it does compile. Please include compilation errors in future, it helps folks to figu

Very Stupid Regex question

2014-08-07 Thread seany via Digitalmars-d-learn
Cosider please the following: string s1 = PREabcdPOST; string s2 = PREabPOST; string[] srar = ["ab", "abcd"]; // this can not be constructed with a particular order foreach(sr; srar) { auto r = regex(sr; "g"); auto m = matchFirst(s1, r); break; // this one matches ab // but I want t

Re: Very Stupid Regex question

2014-08-07 Thread Justin Whear via Digitalmars-d-learn
On Thu, 07 Aug 2014 16:05:16 +, seany wrote: > obviously there are ways like counting the match length, and then using > the maximum length, instead of breaking as soon as a match is found. > > Are there any other better ways? You're not really using regexes properly. You want to greedily m

Re: Very Stupid Regex question

2014-08-07 Thread via Digitalmars-d-learn
On Thursday, 7 August 2014 at 16:05:17 UTC, seany wrote: Cosider please the following: string s1 = PREabcdPOST; string s2 = PREabPOST; string[] srar = ["ab", "abcd"]; // this can not be constructed with a particular order foreach(sr; srar) { auto r = regex(sr; "g"); auto m = matchFirst(s

Re: Very Stupid Regex question

2014-08-07 Thread seany via Digitalmars-d-learn
On Thursday, 7 August 2014 at 16:12:59 UTC, Justin Whear wrote: On Thu, 07 Aug 2014 16:05:16 +, seany wrote: obviously there are ways like counting the match length, and then using the maximum length, instead of breaking as soon as a match is found. Are there any other better ways? You

Re: Very Stupid Regex question

2014-08-07 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 07, 2014 at 04:49:05PM +, seany via Digitalmars-d-learn wrote: > On Thursday, 7 August 2014 at 16:12:59 UTC, Justin Whear wrote: > >On Thu, 07 Aug 2014 16:05:16 +, seany wrote: > > > >>obviously there are ways like counting the match length, and then > >>using the maximum length

Re: Very Stupid Regex question

2014-08-07 Thread Justin Whear via Digitalmars-d-learn
On Thu, 07 Aug 2014 10:22:37 -0700, H. S. Teoh via Digitalmars-d-learn wrote: > > So basically you have a file containing regex patterns, and you want to > find the longest match among them? > // Longer patterns match first patterns.sort!((a,b) => a.length > > b.length); > > /

Re: Very Stupid Regex question

2014-08-07 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 07, 2014 at 05:33:42PM +, Justin Whear via Digitalmars-d-learn wrote: > On Thu, 07 Aug 2014 10:22:37 -0700, H. S. Teoh via Digitalmars-d-learn > wrote: > > > > > So basically you have a file containing regex patterns, and you want > > to find the longest match among them? > > >

Re: Very Stupid Regex question

2014-08-07 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 07, 2014 at 10:42:13AM -0700, H. S. Teoh via Digitalmars-d-learn wrote: [...] > Hmm, you're right. I was a bit disappointed to find out that the | > operator in std.regex (and also in Perl's regex) doesn't do > longest-match but first-match. :-( I had always thought it did > longest-ma

Re: Very Stupid Regex question

2014-08-07 Thread seany via Digitalmars-d-learn
On Thursday, 7 August 2014 at 18:16:11 UTC, H. S. Teoh via Digitalmars-d-learn wrote: https://issues.dlang.org/show_bug.cgi?id=13268 T Thank you soo much!!