www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Regexp help (possible bug?)

reply gareis <dhasenan gmail.com> writes:
---
import std.regexp;
int main () {
    char[] foo = "foo = bar";
    int i = std.regexp.find(foo, "[^\\]#");
    return 0;
}
---

This outputs "Error: invalid range". According to the documentation, this
should return -1, since the input does not contain an octalthorpe (#) that is
not preceded by a backslash.

Adding an octalthorpe doesn't help matters; it produces the same error. Also,
adding the attribute argument doesn't help.

With an example this small, I think this is probably a bug, but I'd like to
check here before submitting a report -- am I doing something wrong?
May 26 2007
parent reply gareis <dhasenan gmail.com> writes:
Argh -- forget that. I forget that regexps require an extra level of escaping;
that should have been:
---
std.regexp.find(foo, "[^\\\\]#");
---

This is why I ask now rather than submitting bug reports first.

Thanks!
May 26 2007
next sibling parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"gareis" <dhasenan gmail.com> wrote in message 
news:f399o6$n1f$1 digitalmars.com...
 Argh -- forget that. I forget that regexps require an extra level of 
 escaping;
 that should have been:
 ---
 std.regexp.find(foo, "[^\\\\]#");

If you use WYSIWYG strings, you can avoig the ugly double escaping: std.regexp.find(foo, r"[^\\]#"); or std.regexp.find(foo, `[^\\]#`); I've also never heard of a pound sign being called an "octalthorpe"?
May 26 2007
parent reply Deewiant <deewiant.doesnotlike.spam gmail.com> writes:
Jarrett Billingsley wrote:
 I've also never heard of a pound sign being called an "octalthorpe"? 
 

http://en.wikipedia.org/wiki/Number_sign -- Remove ".doesnotlike.spam" from the mail address.
May 26 2007
parent reply Don Clugston <dac nospam.com.au> writes:
Deewiant wrote:
 Jarrett Billingsley wrote:
 I've also never heard of a pound sign being called an "octalthorpe"? 

http://en.wikipedia.org/wiki/Number_sign

(BTW, what do you call ₤?)
May 29 2007
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Don Clugston" <dac nospam.com.au> wrote in message 
news:f3grec$uqq$1 digitalmars.com...

what do you call ??)

Oh I guess that's called a pound sign too, but whenever you say "pound sign" here it means almost certainly #. We might call ? a "British pound sign" or so.
May 29 2007
parent Chris Nicholson-Sauls <ibisbasenji gmail.com> writes:
Jarrett Billingsley wrote:
 "Don Clugston" <dac nospam.com.au> wrote in message 
 news:f3grec$uqq$1 digitalmars.com...
 Where I come from, 'pound sign' has always meant ?, and # is 'hash'. (BTW, 
 what do you call ??)

Oh I guess that's called a pound sign too, but whenever you say "pound sign" here it means almost certainly #. We might call ? a "British pound sign" or so.

I've oft heard it called a "Sterling". -- Chris Nicholson-Sauls
May 29 2007
prev sibling parent davidb <ta-nospam-zz gmx.at> writes:
gareis schrieb:
 Argh -- forget that. I forget that regexps require an extra level of escaping;
 that should have been:
 ---
 std.regexp.find(foo, "[^\\\\]#");
 ---
 
 This is why I ask now rather than submitting bug reports first.
 
 Thanks!

--- int i = std.regexp.find(foo, r"[^\\]#"); --- works as well david
May 26 2007