+ 2
Why Regex() may not work?
I have var chekB = new Regex(@"\w+[k]\b"); and it can't find anything from sentence "I had to kill Frank. Crank". It was just a sentence. So why?
11 Respostas
+ 6
Dead Lord
Add this to the top:
----
using System.Text.RegularExpressions;
----
Change your foreach to this:
----
foreach (var matchB in chekB.Matches(sent)) {
Console.WriteLine(matchB);
}
----
Remove or comment this line, because there isn't a console to read key from on SoloLearn:
----
Console.ReadKey();
----
And remove the crude language in your code. It's just weird.
BTW... If you review my code sample, you will see another option for doing this.
+ 5
Send the link from Regex101.com and a link in Code Playground
+ 5
Dead Lord
See if these codes help you with your issue.
https://regex101.com/r/TMfmot/1
https://code.sololearn.com/c6C913OMYnNF/
+ 4
Groups refer to the sub-matches identified using the parentheses.
Your RegEx pattern contains the grouping between the \b word boundaries.
+ 2
It works on regex101.com
+ 2
David Carroll ty. Later this night I will send it to you
+ 1
Dead Lord Let me know if you have any questions on this.
+ 1
David Carroll code: https://code.sololearn.com/cfm5mBQf41PC/?ref=app
Regex101 link:
https://regex101.com/r/oZj12i/1
+ 1
David Carroll ok. Thank you!
+ 1
Eah, that works. But can you tell me why does this works out?
var chekA = new Regex(@"\b([a-z]{1,4})\b", RegexOptions.IgnoreCase);
Console.WriteLine("a) Вывести только те слова, которые содержат не более 4х букв;");
foreach (Match matchA in chekA.Matches(sent))
{
Console.WriteLine(matchA.Groups[1].Value);
}
+ 1
Actually I want to know why do I need write [1] here:
matchA.Groups[1].Value