c# - Match Specific Printer Command Pattern -


i sending commands printer of format.

{aa00:00;|} {aab08:02;|} 

where { first character, } end character,|is last 1 character. in between these have specific commands aa00:00; , may vary.

i want check these format in regex , new regex, appreciated.

update

i misread comment numbers , thought commas acceptable.

try pattern

"^{[a-z]+\\d+:\\d+;\\|}$" 

breakdown:

  • ^ - beginning of line
  • {[a-z]+ - open bracket following 1 or more capital letters
  • \\d+ - 1 or more numbers
  • : - colon character
  • ; - semi-colon character
  • \\|} - pipe character followed close bracket
  • $ - end of line

code sample:

using system; using system.text.regularexpressions;  public class program {     public static void main()     {         string[] commands =          {             "{aa00:00;|}",             "{abc0:93;||}",             "{aab08:02;|}",             "{123aa:aa;|}",             "{aa123,123:123,123;|}"         };          foreach (string command in commands)         {             if (regex.match(command, "^{[a-z]+\\d+:\\d+;\\|}$").success)             {                 console.writeline("good command");             }             else              {                 console.writeline("bad command");             }         }     } } 

results:

good command bad command command bad command bad command 

demo


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -