Please help with another RegExMatch

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

Please help with another RegExMatch

Post by oldbrother » 06 Dec 2021, 22:22

How can I get the follows from the sample string?

Description: 4 FLUTE REGULAR LENGTH ROUGH & FINSHER 8`% COBALT
Size: 1/4 x 3/8 x 5/8 x 2-7/16

Code: Select all

str =
(
<td><span>73297</span></td>
										</tr>
										<tr>
											<th>Description</th>
											<td>4 FLUTE REGULAR LENGTH ROUGH & FINSHER 8`% COBALT</td>	
										</tr>
										<tr>
											<th>Size</th>
											<td>1/4 x 3/8 x 5/8 x 2-7/16</td>
										</tr>
												
										
										<tr>
											<th>Available Qty.</th>
											
											    <td><b>10</b></td>	
											 
										</tr>
)

sofista
Posts: 645
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: Please help with another RegExMatch

Post by sofista » 06 Dec 2021, 23:04

These regexes seem to work on example data:

Code: Select all

str =
(
<td><span>73297</span></td>
										</tr>
										<tr>
											<th>Description</th>
											<td>4 FLUTE REGULAR LENGTH ROUGH & FINSHER 8`% COBALT</td>	
										</tr>
										<tr>
											<th>Size</th>
											<td>1/4 x 3/8 x 5/8 x 2-7/16</td>
										</tr>
												
										
										<tr>
											<th>Available Qty.</th>
											
											    <td><b>10</b></td>	
											 
										</tr>
)

Template := ".*?<th>(Description|Size)</th>\R\s+<td>([^<]+?)</td>.*"
MsgBox, %  RegExReplace(str, Template Template, "$1: $2`n$3: $4`n")

; or

RegExMatch(str, Template Template, m)
MsgBox, % m1 ": " m2 "`n" m3 ": " m4 "`n"

return

/* Output:

	Description: 4 FLUTE REGULAR LENGTH ROUGH & FINSHER 8% COBALT
	Size: 1/4 x 3/8 x 5/8 x 2-7/16
 */

User avatar
oldbrother
Posts: 273
Joined: 23 Oct 2013, 05:08

Re: Please help with another RegExMatch

Post by oldbrother » 07 Dec 2021, 07:02

Thank you so much! :thumbup: :thumbup: :thumbup:

Post Reply

Return to “Ask for Help (v1)”