c# - Bad Regex performance while searching for times (xx:xx:xx) -
I have to work through a large file (many MBs) and remove the comments from that time Is marked by. An example:
blablabla 12:10:40 I want to remove this blabblabla some more bla after filtering, let me Look like this:
blablabla blablabla something more bla The best way to do this is to be a Regex easier:
Dataout = Regex.Replace ("[012] [0123456789]: [012345] [0123456789]: [012345] [0123456789]. *", String., Blank, regedx option, compact); Now it works perfectly for my purposes, but it is a bit slow. I am assuming this because the first two letters [012] and [0123456789] Accounts are data (this is the ASCII file containing hexadecimal data, such as "0045ab0123" etc.). So the Rexx is making a match on the first two letters.
When I change Regex to
Dataout = Regex. (Change, ": [012345] [0123456789]: [012345] [0123456789]. *", String, Empty, Regex Option. Compact); This may be a very fast speed, probably because all the files ':' are not exactly good! But even then I have to check the first two characters before the first letter number, and then remove the other line.
So my question is:
Or maybe how can I get it? < / Ul>
Or can I find Reggae before for any occurrence of at least times of '': after any match? Is there a better way too?
You can use both of the regular expressions in the question. Possibly a match with colon expression leading to finding or excluding possible lines. If this is successful, then use the full replacement expression.
Match Collection MC = Reggae. Mattas (Dayton, ": [012345] [0123456789]: [012345] [0123456789]. *")); If (MC! = Null & amp; MCLang> gt; 0) {Dataout = Reggae. Replay (date, "[012] [0123456789]: [012345] [0123456789]: [012345] [0123456789]. *", String., Empty, RegexOptions.Compiled); } Else {Dataout = Datain; } There may be a difference
Regex finder = new reggae (": [012345] [0123456789]: [012345] [0123456789]. * "); Reggae Converter = New Reggae ("[012] [0123456789]: [012345] [0123456789]: [012345] [0123456789]. *"); If (Finder Match (Daten). Success) {Dataout = Changer. Replace (date, string.optim); } Else {Dataout = Datain; } One more change is to use the finder as above if the string is found, simply check that the last two letter digits are or not.
Reggae Finder = New Reggae (": [012345] [0123456789]: [012345] [0123456789]. *"); Match Me = Finder Match (Dayton); If (M. seewizz and m.index> gt; 1) {if (char.IsDigit (DataIn [m.index-1]) & amp; amp; amp; amp; four.ISDigit (DataIn [ M.index-2]) {Dataout = m.index-2 == 0? String.Empty: DataIn.Substring (0, m.Index-2);} and {Dataout = Datain;}} and {Dataout = Datain ;}Finderandconvertermust be declared and honored before reading any line in the second and third thoughts. There is no need for new Reggae (...) inside the line reading loop.
Comments
Post a Comment