This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I have following logfile
10:12:28.571 INFO INFO McEvent (ExitWaitPostProcess) Stage: 2
10:12:28.571 INFO McReplay:StatusEvent: 0C0000004576656E74496E666F207631260000000A000000484C4D494E464F207631C0A80A0100007F0000010000010100000000000100000046658FDC5008000000303331333030303115000000
5761697420666F7220706F73742070726F636573735E00000045786974205761697420666F7220706F73742070726F63657373205374616765204E6F322C20592D617869732846726F6E742053696465292C202852656172204C616E65292C205043422049443A20202020202020202020202020202020
10:12:28.571 INFO McReplay:StatusEvent verbose: event:03130001, msg:'Wait for post process', submsg:'Exit Wait for post process Stage No2, Y-axis(Front Side), (Rear Lane), ID: '
10:12:28.571 INFO INFO McEvent (ExitWaitPostProcess) Stage: 2
How should my Regex look like to extract what is coming after McReplay till first line that begins with the time stamp.I have several occurrences in the file and I need all of them.
I thought about something similar to
new Regex(#"^(\d\d:\d\d:\d\d\.\d\d\d) INFO McReplay:(.*?)(\d\d:\d\d:\d\d\.\d\d\d)",
RegexOptions.Singleline | RegexOptions.Multiline);
Seems I have issue with this part (.*?)(\d\d:\d\d:\d\d\.\d\d\d)
What should I fix here ?
This will find all occurrences
List<string> results = new List<string>();
MatchCollection mc = Regex.Matches("yourstring", "McReplay:(.+?)[0-9]{2}:[0-9]{2}:[0-9]{2}", RegexOptions.Singleline);
foreach (Match item in mc)
{
results.Add(item.Result("$1"));
}
Related
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I need a regex to match any p tag that has one or more strike tags inside it.
For example:
<p><strike>Match this</strike></p>
<p style="">Hey! <strike>Match this</strike> also</p>
<p><strike>Match this</strike> entire <strike>p tag</strike></p>
Thanks!
You can use this regex
<p[^<>]*>.*?<strike>.*?</p>
But parsing an html with regex is not recommended method.
Instead use an html parser like htmlagilitypack..
You can use this code to retrieve it using HtmlAgilityPack
HtmlDocument doc = new HtmlDocument();
doc.Load(yourStream);
//strikeNodes contains all the p nodes
var strikeNodes = doc.DocumentNode.SelectNodes("//p[strike]");
//pText contains all p nodes in textual format
List<string> pText= doc.DocumentNode.SelectNodes("//p[strike]").Select(x=>x.OuterHtml);
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
The code:
'Files' is a List<string> and _indx is an int.
label22.Text = files[_indx];
For example in 'files' in index[0] I have this string:
D:\New folder (45)\converted.avi_Automatic\Lightning 0 Length 2 [91 - 93]\000091.bmp
But instead in label22.Text I want it to show me only '000091.bmp' without the rest of the directory path.
How can I do it ?
Use Path.GetFileName:
label22.Text = Path.GetFileName(files[_indx]);
I believe you are looking for Path.GetFileName():
label22.Text = Path.GetFileName(files[_indx]);
Path.GetFileName(fileName) returns the file name without the directory.
taken from http://msdn.microsoft.com/en-us/library/system.io.path.getfilename(v=vs.100).aspx
The simplest way is
Path.GetFileName(files[_indx]);
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I want to retrieve a number from a string wherever the number starts with 8,9 or 6 and length of the number should be 8 OR 9 Characters. E.g 92000000,9200 0000,9200-0000.
How about this: (?<!\d)([896]\d{3})(?:[-\s]?)(\d{4})(?!\d).
The (?:[-\s]?) eats the optional delimiters space or dash as a non-capturing group.
You get your number by concatenating the match groups 1 and 2:
var input = new string[] {
"81000000", "92000000", "9200 0000", "9200-0000"
};
var regex = new Regex (#"(?<!\d)([896]\d{3})(?:[-\s]?)(\d{4})(?!\d)");
foreach (var str in input) {
var match = regex.Match (str);
Console.WriteLine ("TEST: {0} {1} - {2}", str, match.Success,
match.Groups [1].Value + match.Groups [2].Value);
}
I have also tried (?<!\d)([896]\d{3}(?:[-\s]?)\d{4})(?!\d) and that won't remove the delimiter character from the match result.
Try the below regex:
(?<!\d)[896]\d{3}([- ]?)\d{4}(?!\d)
Try to solve using Regexpal from next time.
Cheers.
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I want to find the regex pattern to find the text between a string and a char and replace spaces in the text with _.
Example. < Node Type="Text">Event Log < /Node >
Expected output : Event_Log
Thanks in advance. Please help.
string s = "here is my text $$$ Hello World </stop>";
Match m = Regex.Match(s, "(\\$[^<]*)<");
if (m.Success)
{
Console.WriteLine(m.Groups[1].Value);
}
string str = "$$$ Hello World </stop>";
string sPattern = "[\\$]{3}([\\d\\s\\w]*)</stop>";
Match m = Regex.Match(str, sPattern, RegexOptions.IgnoreCase);
if (m.Success) {
Console.WriteLine(m.Groups(1));
}
Converted from VB code and not tested after but should be ok.
Assuming the example is correct and the text of your question wrong, you need:
\$+[^$<]*(?=<)
If it's the other way around, try this:
(?<=\$+)[^$<]*<
BTW, all questions like this can be more easily answered using a tool like this online regex tester.
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
How do I check if the string reader has passed a certain line number, or has passed a line number which contains some text? I put this in the line processing code of a string reader:
if (currentline.Contains("123"))
currentbank = "123";
else if (currentline.Contains("456"))
currentbank = "456";
else if (currentline.Contains("789"))
currentbank = "789";
I want to change the contents of a string based on what range of line numbers it is in, with my code it always gives 123. Like for example if it's from lines 10-20 (or from 123 to 456) then the string should have 123, 20-30 (or 456 to 789) it should have 456 and 30-40 have 789. How can I do this using a StringReader?
Fixed it myself, problem being I used upper case (e.g. TEST) instead of lower case.