RegExMatch question.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
oldbrother
Posts: 275
Joined: 23 Oct 2013, 05:08

RegExMatch question.

12 May 2023, 22:38

This test code is working properly:

Code: Select all

Data=
(
TEST
CUSTOMER COPY
Dataaaaa
Databbbb
PAGE 1 OF 2Order Confirmation
QUANTITY
CUSTOMER COPY
Data1
Data2
814 PCS(SETS) TOTAL
SUB TOTAL:
PAGE 4 OF 4 TOTAL:100    
)

Needle := "iUm)CUSTOMER COPY(.*)((PAGE \d)|(\n\d+ PCS))"

spo:=1
while (fpo:=RegexMatch(Data, Needle, m, spo))
    {
        spo := fpo + StrLen(m)
        Msgbox %  m1 
    }
However, if I copy the Data text to the Clipboard, the following code doesn't work. Please help me to fix the problem. Thank you!

Before running the code, copy the Data text in the sample code above.

Code: Select all

Data := Clipboard
Needle := "iUm)CUSTOMER COPY(.*)((PAGE \d)|(\n\d+ PCS))"

spo:=1
while (fpo:=RegexMatch(Data, Needle, m, spo))
    {
        spo := fpo + StrLen(m)
        Msgbox %  m1 
    }
User avatar
Datapoint
Posts: 311
Joined: 18 Mar 2018, 17:06

Re: RegExMatch question.

12 May 2023, 23:11

Try adding the s option.

My guess would be that your test script only has newline characters (`n) at the end of each line, but it has carriage return & newline (`r`n) when the text is on your clipboard.

. doesn't match what regex considers a "newline sequence" (`r`n), but it does match `n alone.

The `a option controls this behavior.
User avatar
oldbrother
Posts: 275
Joined: 23 Oct 2013, 05:08

Re: RegExMatch question.

13 May 2023, 10:28

It works! Thank you!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: DecimalTurn, macromint, peter_ahk and 350 guests