Problem with RegExp

Matthew matthewcsims at gmail.com
Wed Jan 2 11:35:32 PST 2008


I was playing around with RegExp and noticed it is not working like I think it should be working. This is the same with both 1.0 and 2.0.

import std.stdio;
import std.regexp;

void main (char [][] args) {
    string text = "Why doesn't it find the sssss's?";

    RegExp pattern = new RegExp(r"[^\s]+"); 
   //Notice the escape code in the expression.

    RegExp list = pattern.search(text);

    foreach(m; list) {
        writefln(m.match(0));
    }

}

The regular expression should match one or more non-whitespace characters. On my comp the whitespace characters don't match, but neither do lower case s's. Interestingly enough if I try the following.

RegExp pattern = new RegExp(r"[^\W]+");

I get the exact same behavior except now capitol W's aren't matched instead of lower case s's. I don't know if this is a bug or not as I've never used RegExp class before, but I wonder if it does this for everyone?



More information about the Digitalmars-d mailing list