Allow only A-I 0-9 and the symbols $# (RegEX)

I`m currently working on a student project in C#, and I want to check if a string contains only the following characters:

A-I 0-9 $ #

The original string:

string rawData ="$A008B20130503C103804D00000000E1022F0080G0128H022I022#";

My code is as follows:

string regEXstring = @"^[A-I0-9$#]+$";
Regex regex = new Regex(regEXstring);
if (regex.IsMatch(rawData))
       dataOK = true;
       dataOK = false;

What am I doing wrong?


Fixing your rawdata/rawData typo, the code works fine. The dataOK variable becomes true with your example data, and false if one adds other characters to the string.

Judging from your example data, you can improve the verification so that you can also determinte that:

  • the string starts with $
  • the string ends with #
  • the strings contains entities that consist of a single character followed by at least three digits

For that, use a pattern like:

string regEXstring = @"^\$([A-I]\d{3,})+#$";

Need Your Help

Rails query slow but fast in pgAdmin

postgresql ruby-on-rails-4 jruby

I'm trying to figure out why one of the queries in my rails app is under performing quite considerably. I'm using Postgres 9.3, and rails 4.0.3 with jRuby 1.7.10 so potentially it's an issue with the

spritecollide and killing sprites

python python-2.7 python-3.x pygame

I have two sprite groups, ship_list has 20 ship sprites, and all_sprites has those 20 sprites, plus the player sprite. In the main loop, when a collision is detected between the player and anything...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.