Kyan Posted March 28, 2015 Posted March 28, 2015 I'm having a bit of trouble using StringRegExpReplace, I wanted to merge Product column to Description column but StringRegExpReplace replaces all to the first match. $t='<tr><td rowspan="1" colspan="1" data-title="Product">Windows 8</td><td rowspan="1" colspan="1" data-title="Description">Country variant</td><td rowspan="1" colspan="1" data-title="Release">RTM</td></tr><tr><td rowspan="1" colspan="1" data-title="Product">windows 8.1</td><td rowspan="1" colspan="1" data-title="Description">Country variant</td><td rowspan="1" colspan="1" data-title="Release">RTM</td></tr>' $r = StringRegExpReplace($t,'(?ims)<td .+? data-title="Product">(.+?)</td><td .+? data-title="Release">(.+?)</td>','\1 \[\2\]') ConsoleWrite(@error&@LF&$r&@LF) Exit Output (Red color=Bad replacement): <tr>Windows 8 [RTM]windows 8.1 [RTM]<td rowspan="1" colspan="1" data-title="Release">RTM</td></tr> Expected (Green color=Good replacement): <tr><td rowspan="1" colspan="1" data-title="Product">Windows 8 [RTM]</td><td rowspan="1" colspan="1" data-title="Description">Country variant</td><td rowspan="1" colspan="1" data-title="Release">RTM</td></tr><tr><td rowspan="1" colspan="1" data-title="Product">windows 8.1 [RTM]</td><td rowspan="1" colspan="1" data-title="Description">Country variant</td><td rowspan="1" colspan="1" data-title="Release">RTM</td></tr> I'm doing like this to after use StringRegExp($rTable,'(?ims)<td .+? data-title="Product">(.+?)</td>',3) and capture everything already on Product [Release] format Heroes, there is no such thing One day I'll discover what IE.au3 has of special for so many users using it.C'mon there's InetRead and WinHTTP, way better
jguinch Posted March 28, 2015 Posted March 28, 2015 I think you have to retrieve the release value before (not sure you can do it in just one shot) $t='<tr><td rowspan="1" colspan="1" data-title="Product">Windows 8</td><td rowspan="1" colspan="1" data-title="Description">Country variant</td><td rowspan="1" colspan="1" data-title="Release">RTM</td></tr><tr><td rowspan="1" colspan="1" data-title="Product">windows 8.1</td><td rowspan="1" colspan="1" data-title="Description">Country variant</td><td rowspan="1" colspan="1" data-title="Release">RTM</td></tr>' $r = StringRegExpReplace($t, 'Product">[^<]+\K', ' [' & StringRegExpReplace($t, '(?s).+Release">([^<]+).+', '$1' ) & ']') ConsoleWrite(@error&@LF&$r&@LF) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Kyan Posted March 28, 2015 Author Posted March 28, 2015 it's working, didn't knew I could intercalate SRER commands thought it would run first StringRegExpReplace($t, '(?s).+Release">([^<]+).+', '$1' ) and then the main SRER Thank you jquinch! Heroes, there is no such thing One day I'll discover what IE.au3 has of special for so many users using it.C'mon there's InetRead and WinHTTP, way better
Kyan Posted March 28, 2015 Author Posted March 28, 2015 UPS nope, it picks the last return from the inside SRER and uses it for all of them #include <Array.au3> $t='<tr><td rowspan="1" colspan="1" data-title="Product">Windows 8</td><td rowspan="1" colspan="1" data-title="Description">Country variant</td><td rowspan="1" colspan="1" data-title="Release">RTM</td></tr><tr><td rowspan="1" colspan="1" data-title="Product">windows 8.1</td><td rowspan="1" colspan="1" data-title="Description">Country variant</td><td rowspan="1" colspan="1" data-title="Release">Technical Preview</td></tr>' $r = StringRegExpReplace($t, 'Product">[^<]+\K', ' [' & StringRegExpReplace($t, '(?s).+Release">([^<]+).+', '$1' ) & ']') $os = StringRegExp($r,'(?ims)<td .+? data-title="Product">(.+?)</td>',3) _ArrayDisplay($os) Exit Returns Row|Col 0 [0]|Windows 8 [Technical Preview] [1]|windows 8.1 [Technical Preview] Heroes, there is no such thing One day I'll discover what IE.au3 has of special for so many users using it.C'mon there's InetRead and WinHTTP, way better
Solution jguinch Posted March 28, 2015 Solution Posted March 28, 2015 (edited) Sorry, I didn't understand what was the expected result. #include <Array.au3> $t='<tr><td rowspan="1" colspan="1" data-title="Product">Windows 8</td><td rowspan="1" colspan="1" data-title="Description">Country variant</td><td rowspan="1" colspan="1" data-title="Release">RTM</td></tr><tr><td rowspan="1" colspan="1" data-title="Product">windows 8.1</td><td rowspan="1" colspan="1" data-title="Description">Country variant</td><td rowspan="1" colspan="1" data-title="Release">Technical Preview</td></tr>' $aRet = StringRegExp($t, '"(?:Product|Release)">([^<]+)', 3) For $i = 0 To UBound($aRet) - 1 Step 2 ConsoleWrite($aRet[$i] & " [" & $aRet[$i + 1] & "]" & @CRLF) Next Edited March 28, 2015 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Kyan Posted March 29, 2015 Author Posted March 29, 2015 Sorry, I didn't understand what was the expected result. #include <Array.au3> $t='<tr><td rowspan="1" colspan="1" data-title="Product">Windows 8</td><td rowspan="1" colspan="1" data-title="Description">Country variant</td><td rowspan="1" colspan="1" data-title="Release">RTM</td></tr><tr><td rowspan="1" colspan="1" data-title="Product">windows 8.1</td><td rowspan="1" colspan="1" data-title="Description">Country variant</td><td rowspan="1" colspan="1" data-title="Release">Technical Preview</td></tr>' $aRet = StringRegExp($t, '"(?:Product|Release)">([^<]+)', 3) For $i = 0 To UBound($aRet) - 1 Step 2 ConsoleWrite($aRet[$i] & " [" & $aRet[$i + 1] & "]" & @CRLF) Next I done almost the same, 1regex for which parameter (product and release) and then with a for loop done the same, is not as time consuming as I expected Thank you jguinch Heroes, there is no such thing One day I'll discover what IE.au3 has of special for so many users using it.C'mon there's InetRead and WinHTTP, way better
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now