-
March 8th, 2009, 11:45 PM
#1
Regular Expression Help
Hi,
I'm having some trouble getting this regular expression to work. I need R1 to match s1 ONLY and R2 to match s2 ONLY. No matter what I do though, R1 matches s2. Here is basicly what I think it should be but I've tried tons over other things. No dice.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Regex R1 = new Regex(@"You partially hit (.+?)(?!.*with.*)for (\d*,?\d+) points of (.+) damage\.");
Regex R2 = new Regex(@"You partially hit (.+) with (.+) for (\d*,?\d+) points of (.+) damage\.");
string s1 = "You partially hit Roryk for 37 points of Shadow damage.";
string s2 = "You partially hit Pongsakorn with Pounce for 99 points of Shadow damage.";
if (R1.IsMatch(s1))
{
Console.WriteLine("Match #1");
}
if (R1.IsMatch(s2))
{
Console.WriteLine("Match #2");
}
if (R2.IsMatch(s1))
{
Console.WriteLine("Match #3");
}
if (R2.IsMatch(s2))
{
Console.WriteLine("Match #4");
}
}
}
}
Output:
Match #1
Match #2
Match #4
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|