PDA

View Full Version : RegExpr



mickey
20th September 2007, 11:35
Hello, I have to define a reg expression and I read one way is to use verbatim keyword to avoid to use backslash for escape caracter (I think it's more thin). But maybe It's not so better. How do use it? I have to define something line [^abc\n"]* and I'm confused now:

Regex regexpr = new Regex(@"[^abc\n"]*");
is it correct? How can I insert " inside verbatim string? It gets error because it expects the end of string......I just write it in C# but maybe will be the same with c++...
thanks.

wysota
20th September 2007, 12:06
Simply escape the backslash with another backslash ([^abc\\n"]).

mickey
20th September 2007, 12:31
sorry but it I have:


string inputString = @"1992
188"; if I have ([^abc\\n"]) the newline is recognized; and it shouldn't be; the newline isn't recognized if I have ([^abc\n"]) with one \
I thought that was right; my question was on "
Sorry but with some prove, I see that to use " inside literal with meaning I need, it should be double quote ( ""):


string inputString = @"19""92"
regXep = ......([^abc\n""])
In this way I have string 19"92 and it doesn't recognized in one token but in two: 19 and 92.
Is right? (for \n: it seems works without \\ but with only one)....

wysota
20th September 2007, 12:45
Escape the quote with an escaped backslash as well :)
[^abc\n\\"]

mickey
20th September 2007, 13:53
Escape the quote with an escaped backslash as well :)
[^abc\n\\"]
It doens't work with \\": compiler see the " as the " of the end of verbatim string......and it gets error...

wysota
20th September 2007, 15:27
Lose the verbatim string. You're escaping special characters to avoid it.

mickey
21st September 2007, 20:15
Hello, I've got this problem here:


@"(?<first>[a-z]+)?(?<second>hello\(\))"

I just want recognize hello() in <second> group;
<first> can recognize:
ffddfhello
ffffhello
helloWorld
hello
helloffffff
But I can't recognized hello() in the second group........when input string is hello() I can see that hello (and only hello) is recognize by first (instead hello() must be recognized by second enterely....)
Is there an error please?

mickey
22nd September 2007, 12:28
hi, is there a way to say in the <first> :"don't recognize 'hello()' "?