RegExMatch does not work as I expect Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
alfema
Posts: 32
Joined: 04 Sep 2015, 11:04

RegExMatch does not work as I expect

01 Dec 2018, 16:57

Hello all:

My version of AutoHotKey is the 1.1.26.1 32 bits on Windows 10 64 bits, same problem in Windows 7 32 bits

Code: Select all

wCMD =
(
view @ XXXXX5579666847> show dsl stats

adsl: ADSL driver and PHY status
Status: Showtime
Number of Cuts:	0
Last Retrain Reason:	8000
Last initialization procedure status:	0
Max:	Upstream rate = 752 Kbps, Downstream rate = 6020 Kbps
Bearer:	0, Upstream rate = 758 Kbps, Downstream rate = 5122 Kbps

Link Power State:	L0
Mode:			ADSL2+ Annex A
TPS-TC:			ATM Mode(0x0)
Trellis:		U:ON /D:ON
Line Status:		No Defect
Training Status:	Showtime
		Down		Up
SNR (dB):	 9.2		 9.4
Attn(dB):	 53.5		 35.9
Pwr(dBm):	 19.3		 12.4

			ADSL2 framing
)

vPos := RegExMatch(wCMD, "Number of Cuts:.+" , SubPat)
If (vPos >  0)
   MsgBox % SubPat
   
First search: Should return "Number of Cuts: 0, but returns all wCMD content from Number of Cuts, included, to the end. Should AutoHotKey not stop searching when finding the CR + LF sequence?. If the m) or DotAll is not used

Second search: If I use "Bearer:.*", same problem, "Bearer:.*Kbps" works!.

Third search, I want to extract the SNR and Attn lines, I use the "SNR((.+)`n`r){2}" search that on another similar occasion worked for me, but not here. The search "SNR ((. +) \ R) {1}" also returns the line Pwr, and "SNR ((. +) \ R) {2}" also returns it.

I tried a string that I picked up from SNR, inclusive, telling him to stop Pwr, but I can not deny Pwr to remove it from the result. ej. "SNR.+Pwr"

Thank you in advance for the help you can give me and, excuse my bad English.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: RegExMatch does not work as I expect

01 Dec 2018, 17:16

this regex needs a multiline flag m, end of line anchor $ and the newline char specified `n or `a, if u wanna use it that way:
"`nm)Number of Cuts:.+$"
alfema
Posts: 32
Joined: 04 Sep 2015, 11:04

Re: RegExMatch does not work as I expect

01 Dec 2018, 17:56

Thanks @swagfaf, but that search is the one that least worries me because I can get the result with "Number of Cuts: (\ s +) (\ d`)", which I use elsewhere to extract the numeric value in Subpat2.

I am more interested in solving the third search because I need it in other searches and I am curious to know if jumping the CR and LF is the normal behavior, as you read it must be used m) or DotAll to do it.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: RegExMatch does not work as I expect

01 Dec 2018, 18:28

ah i didnt read this, lol
Should AutoHotKey not stop searching when finding the CR + LF sequence?. If the m) or DotAll is not used
By default, a dot matches any single character which is not part of a newline (`r`n) sequence, but this can be changed by using the DotAll (s), linefeed (`n), carriage return (`r), `a or (*ANYCRLF) options. For example, ab. matches abc and abz and ab_.
it should and it does. its just that the way ure presenting the string(a continuation section with the default options, ie `n as a newline character) makes it fail. the . in this case wont match only if it sees `r`n. all other cases are fair game. u can test this by changing ur continuation section to use Join`r`n instead.

on the actual question of how to parse this, the easiest way would be the way i described, eg for SNR:

Code: Select all

RegExMatch(wCmd, "`am)^SNR\D*(?P<Down>\S+)\s*(?P<Up>\S+)", Snr) ; ie, SNR -> not digits -> not whitespaces(store in SnrDown) -> whitespaces -> not whitespaces(store in SnrUp)
MsgBox % SnrDown
MsgBox % SnrUp
alfema
Posts: 32
Joined: 04 Sep 2015, 11:04

Re: RegExMatch does not work as I expect  Topic is solved

16 Dec 2018, 12:31

Finally I found the solution to what I wanted to do.

Code: Select all

RegExMatch(wCmd, "(SNR.+)\bPwr", SNRAttn)

MsgBox % SNRAttn1

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Marium0505, mcl and 336 guests