I need a regex to not match tab, carriage return and square brackets. (C#)
+2
A:
Try:
[^\][\t\r]
[]
- char class^
- negation of char class.\]
- escape ] as ] is a meta char inside a char class[
- need not escape[
as inside[]
its not a meta char\t
- tab\r
- return carriage
codaddict
2010-03-05 17:11:00
I think you are missing `\n` in symbol class
Ivan Nevostruev
2010-03-05 17:12:47
OP doesn't mention new-lines.
Douglas Leeder
2010-03-05 17:13:40
\n is newline, he only asked for carriage return which is \r
fuzzy lollipop
2010-03-05 17:14:09
I hope OP author knows what he's asking for
Ivan Nevostruev
2010-03-05 17:16:46
Agreed: it's ugly either way, but it's a little less confusing with the backslash. Besides, in some flavors you *do* have to escape the `[`.
Alan Moore
2010-03-05 21:43:49
A:
[\w]+
Will match any word character (alphanumeric & underscore).
Marcos Placona
2010-03-05 17:12:54
And what about all the other characters that are not tabs, carriage-returns or square brackets?
Alan Moore
2010-03-05 21:38:42
A:
#!/usr/bin/perl
use strict; use warnings;
my ($s) = @ARGV;
if ( $s =~ /^[^\r\t\[\]]*\z/ ) {
print "$s contains no carriage returns, tabs or square brackets\n";
}
Sinan Ünür
2010-03-05 17:12:58