using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"\$[A-Za-z]{0,4}[0-9]{0,1}";
string input = @"# This is test program 1. This program does nothing useful.
add $s0, $0, $zero
addi $t0, $t0, 100#test comment
addi $a0, $a0,100
test: add $s0, $s0, $a0 # this is a comment
addi $a0, $a0, -1
bne $a0, $0, test # this is another comment
addi $a0, $a0, 100
test1:
#test comment
lw $a0, 8($a1)
sw $a0,4($a1)
j test1
jr $ra
jal test1
slt$t0,$a0,$a1
beq$t0,$t1,test
sub $t3, $t1, $t1
sll $a0, $a1, 2
";
foreach (Match m in Regex.Matches(input, pattern))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx