Sign in to follow this  
Followers 0
d0n

StringRegExp patterns

3 posts in this topic

is there a way to look for match certain words that only show up some of the time?

for example i have a pattern

Jon is hit with arrow for 831 damage

but some times it will say

(Critical Hit) Jon is hit with arrow for 1831 damage

The pattern right now will only catch the first example while not the second because of (Critical Hit)

So far to get the first example i have

(.*?).*?with\s*(.*?)\s*for\s*(\d+)

Share this post


Link to post
Share on other sites



#include <Array.au3>

Dim $aStr[2] = ['Jon is hit with arrow for 831 damage', _
                '(Critical Hit) Jon is hit with arrow for 1831 damage']

Dim $sPattern = '(?i)(?:\(.*?\)\s*)?(\w+).*?with\s*(\w+)\s*for\s*(\d+)'
Dim $avMatch

For $i = 0 To 1
    $avMatch = StringRegExp($aStr[$i], $sPattern, 1)
    If IsArray($avMatch) Then _ArrayDisplay($avMatch)
Next

Share this post


Link to post
Share on other sites

Thank you got it working now

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0