You should take a look at the possibility to name groups in regex patterns; your match pattern can then be a oneliner:
const string pattern = @"^(?<name>\w+)\[(?<index>\d+)\]$";
Match match = Regex.Match(command, pattern);
string featureName = match.Groups["name"].Value;
int index = int.Parse(match....
One possible place you can improve performance is here:
const string pattern = @"\[(.*?)\]";
var query = command;
var matches = Regex.Matches(query, pattern); //Gets anything inside the brackets
index = Convert.ToInt32(matches.Groups.Value); //should be an int
featureName = command.Substring(0, command.IndexOf('[')).ToUpper();
Why would you want to use Regular Expressions anyway if the base format of the string is always the same?
Name[Number] seems like an easy pattern. Just iterate through the characters one by one and store all characters in the first string until you reach the first bracket. Then store the numbers in the second string (until you reach the closing bracket). ...
Hash all string constants
I'm presuming you only have a limited number of keywords ("move", "vertex" etc.). Hash all of those with something fast - CRC32 is perfectly adequate.
Split the string into space-separated tokens, as usual, and calculate the hash of the first and second tokens. Then you just need to compare the calculated hash with the hashes of ...
Instead of throwing away that list of GovernmentCsvRecord objects after converting it to a StringCsv list, you could keep it around so you don't have to read the csv file again if the IsNumericFile check fails.
It looks like you can validate the list of GovernmentCsvRecord objects directly instead of first converting them to StringCsv objects. However, with ...
Your expression looks just fine, maybe we would slightly modify that to:
for failing these samples, 3., 4., for instance, just in case maybe such samples might be undesired. Other than that, you have some capturing groups that I'm guessing you'd like to keep those.
Test the capturing groups with re.finditer
The first obvious optimization would be to not call Regex.Matches(string, string) which compiles the regular expression every single time. Compiling the regex is an expensive operation.
Instead, create a Regex (which compiles the expression exactly once) and keep it around during your several thousand invocations. That should by itself do the trick (because,...
Well, your regex solution is obviously badly broken - it will fail if the attributes are in a different order, if they are separated by newlines, if they are delimited by single quotes, etc etc. If you try to replace it with a more correct regex (it will never be 100% correct of course) then you are quite likely to lose some of this speed - perhaps ...
On my windows 10 laptop, I ran your program on a dummy log file under the python
profiler using the command line:
python -m cProfile -s cumulative loggrep.py "speech" \data\test.log
The dummy log file has about 4.3 Mbytes of text spread across about 100k lines
comprising 32772 log entries. The search pattern was "speech", which occured
In theory, you're going to want to call this function more than once. That means that you only want to pay the cost of regex compilation once, and you should move your re.compile calls out of the function, setting your regex variables in the module's global scope.
s is s: str, and char is (I think) also char: str.