Jump to content

StringRegExp patterns


 Share

Recommended Posts

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+)

Link to comment
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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...