I am trying to find the number of matches in a relative path for reference links (" ..\"). So I have the following template: " (\.\.\\)", which works as expected for the path " ..\..\a\b", where it will give me two successful groups (" ..\"), but when I try the path " ..\a\b" it will also return 2 when it will return 1. I tried this in a reg ex tool like Expresso and it seems to work as expected, but not in .net, any ideas?
..\
(\.\.\\)
..\..\a\b
..\a\b
I get the correct answer, try the following:
Console.WriteLine(Regex.Matches(@"..\..\a\b", @"(\.\.\\)").Count); //2 Console.WriteLine(Regex.Matches(@"..\a\b", @"(\.\.\\)").Count); //1
\ .NET?
\
:
(.) , . , .
.
Expresso .net, " reg ex, Expresso, , , , .net", , ., , , . Regex, , , .
Hope this helps!
Did you run back to avoid points in the Regex? That is, "\\.\\.\\\\"or @"\.\.\\"?
"\\.\\.\\\\"
@"\.\.\\"
You can always not use Regex for this task and use
Int32 count = url.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries) .Where(s => s == "..") .Count();
instead of this. =)
Source: https://habr.com/ru/post/1737539/More articles:C ++ simple conditional log - c ++Maven: не удалось установить стороннюю банку - maven-2TryGetValue () in a linq expression with anonymous types - c #Athena Common Build for Eclipse Goal and Benefits - buildNHibernate: how to get the displayed values? - nhibernatePHP Server Side Post to Re-create Secure Single Sign-On Replacement - posthttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1737541/in-maven-2-is-it-possible-to-specify-a-mirror-for-everything-but-allow-for-failover-to-direct-repositories&usg=ALkJrhiR7fvzhDEO_VIIslVQ-PfaMq3RiQClass plugins in PHP? - phpHow to read tables with Hebrew column names (in R)? - rDjango requests: number of instances with an FK instance for the model - djangoAll Articles