C
cupboy1
Guest
Well I have 2 problems.
Capture[0] should just be the number.
Here is the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string x = @"c:\whirlwind\\Customer Support_backup011.bak";
Regex r1 = new Regex("[0-9]{3}.bak");
Console.WriteLine(r1.IsMatch(x));
string pattern1 = "([0-9]{3}).bak";
MatchCollection m1 = Regex.Matches(x, pattern1);
int count1 = m1.Count;
Console.WriteLine("Count of matches:" + count1.ToString());
if (count1 > 0) {
Console.WriteLine(m1[0]);
Match m0 = m1[0];
Group g1 = m0.Groups[0];
CaptureCollection c1 = g1.Captures;
Console.WriteLine("Captures: " + c1.Count.ToString());
if (c1.Count > 0) {
Capture c0 = c1[0];
Console.WriteLine("Capture[0] = " + c0);
}
Console.WriteLine("Captures count: " + c1.Count.ToString());
}
Console.ReadLine();
}
}
}
/*
True
Count of matches:1
011.bak
Capture[0] = 011.bak (This should just be 011)
Captures count: 1
Changes are not allowed while code is running (another problem, and yes the box is checked to enable it)
*/
Continue reading...
Capture[0] should just be the number.
Here is the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string x = @"c:\whirlwind\\Customer Support_backup011.bak";
Regex r1 = new Regex("[0-9]{3}.bak");
Console.WriteLine(r1.IsMatch(x));
string pattern1 = "([0-9]{3}).bak";
MatchCollection m1 = Regex.Matches(x, pattern1);
int count1 = m1.Count;
Console.WriteLine("Count of matches:" + count1.ToString());
if (count1 > 0) {
Console.WriteLine(m1[0]);
Match m0 = m1[0];
Group g1 = m0.Groups[0];
CaptureCollection c1 = g1.Captures;
Console.WriteLine("Captures: " + c1.Count.ToString());
if (c1.Count > 0) {
Capture c0 = c1[0];
Console.WriteLine("Capture[0] = " + c0);
}
Console.WriteLine("Captures count: " + c1.Count.ToString());
}
Console.ReadLine();
}
}
}
/*
True
Count of matches:1
011.bak
Capture[0] = 011.bak (This should just be 011)
Captures count: 1
Changes are not allowed while code is running (another problem, and yes the box is checked to enable it)
*/
Continue reading...