Jump to content
Sign in to follow this  
Pauletp

StringRegExp syntax question

Recommended Posts

Pauletp

I have a string

"G3A B2 G2|A2 G2 B2 G2|G3A B2 G2|A2 G2 E4|G3A B2 G2|A2 G2 B2 d2|G3A G2 E2|E2 D2 D4"

In the tutorial on regular expressions in the Help file there is a GUI (StringRegExpGUI.au3) to test results with StringRegExp

If I input the search string in the GUI to be

([abcdefgABCDEFG]3[abcdefgABCDEFG] [abcdefgABCDEFG]2 [abcdefgABCDEFG]2)

the GUI shows the result array to be

0 => G3A B2 G2

1 => G3A B2 G2

2 => G3A B2 G2

3 => G3A G2 E2

This is the result I want.

But the code

#Include <Array.au3>
$Source = "G3A B2 G2|A2 G2 B2 G2|G3A B2 G2|A2 G2 E4|G3A B2 G2|A2 G2 B2 d2|G3A G2 E2|E2 D2 D4"
$Filter = "([abcdefgABCDEFG]3[abcdefgABCDEFG] [abcdefgABCDEFG]2 [abcdefgABCDEFG]2)"
$MatchArray = StringRegExp($Source, $Filter,1) 
_ArrayDisplay ($MatchArray, "Display matches")

only displays the first match which is

"G3A B2 G2"

so the syntax must be wrong.

Many thanks if someone has a tip.

Share this post


Link to post
Share on other sites
SmOke_N

StringRegExp($Source, "(?i)([a-g]3[a-g] [a-g]2 [a-g]2)", 3)

Note the "3" in the 3rd parameter. You're only telling it to find the first match.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.