-
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
-
March 9th, 2009, 06:58 PM
#2
Re: Regular Expression Help
Got. Needed to use ?<! which I believe is negative lookbehind, the chart that I was following had it listed as the same as ?!= which I tested instead cause I was loading these from an XML file, where the < is not so friendly.
-
March 10th, 2009, 05:46 PM
#3
Re: Regular Expression Help
If this is already resolved please use the threadtools and sign it as resolved Thx
Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
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
|