json_renlan
json_renlan

Reputation: 41

Regex to not match tab, carriage return and square brackets

I need a regex to not match tab, carriage return and square brackets. (C#)

Upvotes: 4

Views: 12630

Answers (4)

codaddict
codaddict

Reputation: 455322

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

Upvotes: 5

Sinan Ünür
Sinan Ünür

Reputation: 118158

#!/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";
}

Upvotes: 0

Marcos Placona
Marcos Placona

Reputation: 21730

[\w]+

Will match any word character (alphanumeric & underscore).

Upvotes: 0

Kobi
Kobi

Reputation: 138117

should be:

[^\t\r\[\]]

or for the whole string:

^[^\t\r\[\]]*$

Upvotes: 1

Related Questions