fraizor Posted July 20, 2023 Share Posted July 20, 2023 (edited) I was wondering if there is something similar to _StringBetween but where i can define some rules to match I need to match for for the word "Style" in the html text only without the Tags... (the word "style" in black font) This is the original code it searches the whole text (including tags) if StringInStr($DescFile[$i], "Style") then $DescFile[$i] = StringReplace($DescFile[$i],"Style",$DictFile[$n][1]) Endif I tried the following to limit it to search only in the HTML text (without tags) but it did not work (as it always found <> for the word "style") if StringInStr($DescFile[$i], _StringBetween("Style", ">", "<")) then Any ideas ? Note: I know that Regex can solve the problem, but i cant use as this line of code is part from a bigger nested loop , the return value must be a string not an array (StringRegExp returns an array) Edited July 20, 2023 by fraizor AutoFox, A Modern, Simple, No dependency, Noob friendly yet powerful Firefox UDF ! Link to comment Share on other sites More sharing options...
Jfish Posted July 20, 2023 Share Posted July 20, 2023 2 hours ago, fraizor said: Any ideas ? Note: I know that Regex can solve the problem, but i cant use as this line of code is part from a bigger nested loop , the return value must be a string not an array (StringRegExp returns an array) Why not just loop through the array to get the values you want and return them with whatever type suits you? fraizor 1 Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
Musashi Posted July 20, 2023 Share Posted July 20, 2023 2 hours ago, fraizor said: Any ideas ? Note: I know that Regex can solve the problem, but i cant use as this line of code is part from a bigger nested loop , the return value must be a string not an array (StringRegExp returns an array) Use StringRegExpReplace instead. This will return an updated string based on a regular expressions. TheXman and fraizor 2 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
fraizor Posted July 20, 2023 Author Share Posted July 20, 2023 5 minutes ago, Jfish said: Why not just loop through the array to get the values you want and return them with whatever type suits you? I think this would be a little difficult, i am processing HTML markup files one by one to do some text replacement , it is not just pulling data ... AutoFox, A Modern, Simple, No dependency, Noob friendly yet powerful Firefox UDF ! Link to comment Share on other sites More sharing options...
fraizor Posted July 20, 2023 Author Share Posted July 20, 2023 3 minutes ago, Musashi said: Use StringRegExpReplace instead. This will return an updated string based on a regular expressions. Yes, this is a nice idea, but how can i identify that the work is Text not a tag before i replace it ? AutoFox, A Modern, Simple, No dependency, Noob friendly yet powerful Firefox UDF ! Link to comment Share on other sites More sharing options...
Musashi Posted July 20, 2023 Share Posted July 20, 2023 14 minutes ago, fraizor said: Yes, this is a nice idea, but how can i identify that the work is Text not a tag before i replace it ? I'm not quite clear yet what exactly you want to replace with what (probably due to the heat that is currently boiling my brain ). Could you describe your goal a bit more precisely. Also, please post the HTML snippet as text (e.g. as code < >), not as a picture. That way others could test the process without having to type the data from the image. TheXman 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
fraizor Posted July 20, 2023 Author Share Posted July 20, 2023 1 minute ago, Musashi said: I'm not quite clear yet what exactly you want to replace with what (probably due to the heat that is currently boiling my brain ). Could you describe your goal a bit more precisely. Also, please post the HTML snippet as text (e.g. as code < >), not as a picture. That way others could test the process without having to type the data from the image. Sure let me try to explain myself again: I have thousands of html files like these <div><p style="text-align:left;">Style: <span style="float:right;">Casual</span></p></div><div><p style="text-align:left;">Color: <span style="float:right;">Navy Blue</span></p></div><div><p style="text-align:left;">Pattern Type: <span style="float:right;">Plain</span></p></div><div><p style="text-align:left;">Neckline: <span style="float:right;">Round Neck</span></p></div><div><p style="text-align:left;">Length: <span style="float:right;">Long</span></p></div><div><p style="text-align:left;">Type: <span style="float:right;">A Line</span></p></div><div><p style="text-align:left;">Details: <span style="float:right;">Pearls</span></p></div><div><p style="text-align:left;">Details: <span style="float:right;">Frill</span></p></div><div><p style="text-align:left;">Details: <span style="float:right;">Beaded</span></p></div><div><p style="text-align:left;">Details: <span style="float:right;">Pocket</span></p></div><div><p style="text-align:left;">Sleeve Length: <span style="float:right;">Half Sleeve</span></p></div><div><p style="text-align:left;">Season: <span style="float:right;">Spring/Fall</span></p></div><div><p style="text-align:left;">Composition: <span style="float:right;">75% Cotton</span></p></div><div><p style="text-align:left;">Composition: <span style="float:right;">Denim</span></p></div><div><p style="text-align:left;">Composition: <span style="float:right;">25% Polyester</span></p></div><div><p style="text-align:left;">Fabric: <span style="float:right;">Non-Stretch</span></p></div><div><p style="text-align:left;">Waist Line: <span style="float:right;">Natural</span></p></div><br /><table border="1"><thead><tr><th>size</th><th>Shoulder </th><th>Bust </th><th>Waist Size </th><th>Hip Size </th><th>Sleeve Length </th><th>Length </th><th>Bicep Length </th><th>Cuff </th></tr></thead><tbody><tr><td>XS</td><td> 38 cm</td><td> 91 cm</td><td> 90 cm</td><td> 101 cm</td><td> 39 cm</td><td> 139 cm</td><td> 30 cm</td><td> 25 cm</td></tr><tr><td>S</td><td> 39 cm</td><td> 95 cm</td><td> 94 cm</td><td> 105 cm</td><td> 40 cm</td><td> 140 cm</td><td> 31 cm</td><td> 26 cm</td></tr><tr><td>M</td><td> 40 cm</td><td> 99 cm</td><td> 98 cm</td><td> 109 cm</td><td> 41 cm</td><td> 141 cm</td><td> 32 cm</td><td> 27 cm</td></tr><tr><td>L</td><td> 41 cm</td><td> 103 cm</td><td> 102 cm</td><td> 113 cm</td><td> 42 cm</td><td> 142 cm</td><td> 33 cm</td><td> 28 cm</td></tr></tbody></table> I have a dictionary 2D array that have translation for every word (Color, Details, waist size, length ....) i need to replace any word in the dictionary with its corresponding translation .. until now it is easy, the part i am stuck at is identifying the HTML pure text from the HTML tag for example: the word "style" is mentioned couple of times , sometimes it is an actual text and sometimes it is a part of an HTML tag <span style="float:right;"> i need to translate (string replace) the text only and avoid touching the HTML tags ... hope it's clear now thanks in advance ... AutoFox, A Modern, Simple, No dependency, Noob friendly yet powerful Firefox UDF ! Link to comment Share on other sites More sharing options...
ioa747 Posted July 20, 2023 Share Posted July 20, 2023 if StringInStr($DescFile[$i], "Style:") then $DescFile[$i] = StringReplace($DescFile[$i],"Style:",$DictFile[$n][1] & ":") Endif I know that I know nothing Link to comment Share on other sites More sharing options...
fraizor Posted July 20, 2023 Author Share Posted July 20, 2023 1 minute ago, ioa747 said: if StringInStr($DescFile[$i], "Style:") then $DescFile[$i] = StringReplace($DescFile[$i],"Style:",$DictFile[$n][1] & ":") Endif unfortunately that won't work, as the Colon is optional (sometimes the tet i need to replace does not have Colon) AutoFox, A Modern, Simple, No dependency, Noob friendly yet powerful Firefox UDF ! Link to comment Share on other sites More sharing options...
OJBakker Posted July 20, 2023 Share Posted July 20, 2023 Maybe this will catch the Style you want to replace? if StringInStr($DescFile[$i], ">Style") then $DescFile[$i] = StringReplace($DescFile[$i],">Style",">" & $DictFile[$n][1]) Endif Link to comment Share on other sites More sharing options...
fraizor Posted July 20, 2023 Author Share Posted July 20, 2023 9 minutes ago, OJBakker said: Maybe this will catch the Style you want to replace? if StringInStr($DescFile[$i], ">Style") then $DescFile[$i] = StringReplace($DescFile[$i],">Style",">" & $DictFile[$n][1]) Endif What if there is a character before the "<" ? like space ? AutoFox, A Modern, Simple, No dependency, Noob friendly yet powerful Firefox UDF ! Link to comment Share on other sites More sharing options...
TheXman Posted July 20, 2023 Share Posted July 20, 2023 (edited) How about something like this: #AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d Const $HTML = '<div><p style="text-align:left;">Style: <span style="float:right;">Casual</span></p></div><div><p style="text-align:left;">Color: <span style="float:right;">Navy Blue</span></p></div><div><p style="text-align:left;">Pattern Type: <span style="float:right;">Plain</span></p></div><div><p style="text-align:left;">Neckline: <span style="float:right;">Round Neck</span></p></div><div><p style="text-align:left;">Length: <span style="float:right;">Long</span></p></div><div><p style="text-align:left;">Type: <span style="float:right;">A Line</span></p></div><div><p style="text-align:left;">Details: <span style="float:right;">Pearls</span></p></div><div><p style="text-align:left;">Details: <span style="float:right;">Frill</span></p></div><div><p style="text-align:left;">Details: <span style="float:right;">Beaded</span></p></div><div><p style="text-align:left;">Details: <span style="float:right;">Pocket</span></p></div><div><p style="text-align:left;">Sleeve Length: <span style="float:right;">Half Sleeve</span></p></div><div><p style="text-align:left;">Season: <span style="float:right;">Spring/Fall</span></p></div><div><p style="text-align:left;">Composition: <span style="float:right;">75% Cotton</span></p></div><div><p style="text-align:left;">Composition: <span style="float:right;">Denim</span></p></div><div><p style="text-align:left;">Composition: <span style="float:right;">25% Polyester</span></p></div><div><p style="text-align:left;">Fabric: <span style="float:right;">Non-Stretch</span></p></div><div><p style="text-align:left;">Waist Line: <span style="float:right;">Natural</span></p></div><br /><table border="1"><thead><tr><th>size</th><th>Shoulder </th><th>Bust </th><th>Waist Size </th><th>Hip Size </th><th>Sleeve Length </th><th>Length </th><th>Bicep Length </th><th>Cuff </th></tr></thead><tbody><tr><td>XS</td><td> 38 cm</td><td> 91 cm</td><td> 90 cm</td><td> 101 cm</td><td> 39 cm</td><td> 139 cm</td><td> 30 cm</td><td> 25 cm</td></tr><tr><td>S</td><td> 39 cm</td><td> 95 cm</td><td> 94 cm</td><td> 105 cm</td><td> 40 cm</td><td> 140 cm</td><td> 31 cm</td><td> 26 cm</td></tr><tr><td>M</td><td> 40 cm</td><td> 99 cm</td><td> 98 cm</td><td> 109 cm</td><td> 41 cm</td><td> 141 cm</td><td> 32 cm</td><td> 27 cm</td></tr><tr><td>L</td><td> 41 cm</td><td> 103 cm</td><td> 102 cm</td><td> 113 cm</td><td> 42 cm</td><td> 142 cm</td><td> 33 cm</td><td> 28 cm</td></tr></tbody></table>' example() Func example() Local $sUpdatedHtml = $HTML $sUpdatedHtml = _HTML_ReplaceAllText($sUpdatedHtml, "Style" , "MODIFIED_STYLE") $sUpdatedHtml = _HTML_ReplaceAllText($sUpdatedHtml, "style" , "MODIFIED_STYLE") ;Shows that attributes are not modified $sUpdatedHtml = _HTML_ReplaceAllText($sUpdatedHtml, "Casual" , "MODIFIED_CASUAL") $sUpdatedHtml = _HTML_ReplaceAllText($sUpdatedHtml, "Color" , "MODIFIED_COLOR") $sUpdatedHtml = _HTML_ReplaceAllText($sUpdatedHtml, "Sleeve Length" , "MODIFIED_SLEEVE_LENGTH") ConsoleWrite($sUpdatedHtml & @CRLF) EndFunc ;============================================================================== ; Note: The regular expression assumes that the search text is case sensitive. ;============================================================================== Func _HTML_ReplaceAllText($sSource, $sSearchText, $sReplaceText) Return StringRegExpReplace( _ $sSource, _ StringFormat("(>.*?)\\Q%s\\E([^=][^<]*)", $sSearchText), _ "$1" & $sReplaceText & "$2" _ ) EndFunc Output: <div><p style="text-align:left;">MODIFIED_STYLE: <span style="float:right;">MODIFIED_CASUAL</span></p></div><div><p style="text-align:left;">MODIFIED_COLOR: <span style="float:right;">Navy Blue</span></p></div><div><p style="text-align:left;">Pattern Type: <span style="float:right;">Plain</span></p></div><div><p style="text-align:left;">Neckline: <span style="float:right;">Round Neck</span></p></div><div><p style="text-align:left;">Length: <span style="float:right;">Long</span></p></div><div><p style="text-align:left;">Type: <span style="float:right;">A Line</span></p></div><div><p style="text-align:left;">Details: <span style="float:right;">Pearls</span></p></div><div><p style="text-align:left;">Details: <span style="float:right;">Frill</span></p></div><div><p style="text-align:left;">Details: <span style="float:right;">Beaded</span></p></div><div><p style="text-align:left;">Details: <span style="float:right;">Pocket</span></p></div><div><p style="text-align:left;">MODIFIED_SLEEVE_LENGTH: <span style="float:right;">Half Sleeve</span></p></div><div><p style="text-align:left;">Season: <span style="float:right;">Spring/Fall</span></p></div><div><p style="text-align:left;">Composition: <span style="float:right;">75% Cotton</span></p></div><div><p style="text-align:left;">Composition: <span style="float:right;">Denim</span></p></div><div><p style="text-align:left;">Composition: <span style="float:right;">25% Polyester</span></p></div><div><p style="text-align:left;">Fabric: <span style="float:right;">Non-Stretch</span></p></div><div><p style="text-align:left;">Waist Line: <span style="float:right;">Natural</span></p></div><br /><table border="1"><thead><tr><th>size</th><th>Shoulder </th><th>Bust </th><th>Waist Size </th><th>Hip Size </th><th>MODIFIED_SLEEVE_LENGTH </th><th>Length </th><th>Bicep Length </th><th>Cuff </th></tr></thead><tbody><tr><td>XS</td><td> 38 cm</td><td> 91 cm</td><td> 90 cm</td><td> 101 cm</td><td> 39 cm</td><td> 139 cm</td><td> 30 cm</td><td> 25 cm</td></tr><tr><td>S</td><td> 39 cm</td><td> 95 cm</td><td> 94 cm</td><td> 105 cm</td><td> 40 cm</td><td> 140 cm</td><td> 31 cm</td><td> 26 cm</td></tr><tr><td>M</td><td> 40 cm</td><td> 99 cm</td><td> 98 cm</td><td> 109 cm</td><td> 41 cm</td><td> 141 cm</td><td> 32 cm</td><td> 27 cm</td></tr><tr><td>L</td><td> 41 cm</td><td> 103 cm</td><td> 102 cm</td><td> 113 cm</td><td> 42 cm</td><td> 142 cm</td><td> 33 cm</td><td> 28 cm</td></tr></tbody></table> Edited July 20, 2023 by TheXman Added \Q..\E to the regular expression in order to ignore search text that includes regular expression characters. Musashi and Werty 2 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
fraizor Posted July 20, 2023 Author Share Posted July 20, 2023 9 minutes ago, TheXman said: How about something like this: #AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d Const $HTML = '<div><p style="text-align:left;">Style: <span style="float:right;">Casual</span></p></div><div><p style="text-align:left;">Color: <span style="float:right;">Navy Blue</span></p></div><div><p style="text-align:left;">Pattern Type: <span style="float:right;">Plain</span></p></div><div><p style="text-align:left;">Neckline: <span style="float:right;">Round Neck</span></p></div><div><p style="text-align:left;">Length: <span style="float:right;">Long</span></p></div><div><p style="text-align:left;">Type: <span style="float:right;">A Line</span></p></div><div><p style="text-align:left;">Details: <span style="float:right;">Pearls</span></p></div><div><p style="text-align:left;">Details: <span style="float:right;">Frill</span></p></div><div><p style="text-align:left;">Details: <span style="float:right;">Beaded</span></p></div><div><p style="text-align:left;">Details: <span style="float:right;">Pocket</span></p></div><div><p style="text-align:left;">Sleeve Length: <span style="float:right;">Half Sleeve</span></p></div><div><p style="text-align:left;">Season: <span style="float:right;">Spring/Fall</span></p></div><div><p style="text-align:left;">Composition: <span style="float:right;">75% Cotton</span></p></div><div><p style="text-align:left;">Composition: <span style="float:right;">Denim</span></p></div><div><p style="text-align:left;">Composition: <span style="float:right;">25% Polyester</span></p></div><div><p style="text-align:left;">Fabric: <span style="float:right;">Non-Stretch</span></p></div><div><p style="text-align:left;">Waist Line: <span style="float:right;">Natural</span></p></div><br /><table border="1"><thead><tr><th>size</th><th>Shoulder </th><th>Bust </th><th>Waist Size </th><th>Hip Size </th><th>Sleeve Length </th><th>Length </th><th>Bicep Length </th><th>Cuff </th></tr></thead><tbody><tr><td>XS</td><td> 38 cm</td><td> 91 cm</td><td> 90 cm</td><td> 101 cm</td><td> 39 cm</td><td> 139 cm</td><td> 30 cm</td><td> 25 cm</td></tr><tr><td>S</td><td> 39 cm</td><td> 95 cm</td><td> 94 cm</td><td> 105 cm</td><td> 40 cm</td><td> 140 cm</td><td> 31 cm</td><td> 26 cm</td></tr><tr><td>M</td><td> 40 cm</td><td> 99 cm</td><td> 98 cm</td><td> 109 cm</td><td> 41 cm</td><td> 141 cm</td><td> 32 cm</td><td> 27 cm</td></tr><tr><td>L</td><td> 41 cm</td><td> 103 cm</td><td> 102 cm</td><td> 113 cm</td><td> 42 cm</td><td> 142 cm</td><td> 33 cm</td><td> 28 cm</td></tr></tbody></table>' example() Func example() Local $sUpdateHtml = $HTML $sUpdateHtml = _HTML_ReplaceAllText($sUpdateHtml, "Style" , "MODIFIED_STYLE") $sUpdateHtml = _HTML_ReplaceAllText($sUpdateHtml, "style" , "MODIFIED_STYLE") ;just to show nothing is modified $sUpdateHtml = _HTML_ReplaceAllText($sUpdateHtml, "Casual", "MODIFIED_CASUAL") $sUpdateHtml = _HTML_ReplaceAllText($sUpdateHtml, "Color" , "MODIFIED_COLOR") ConsoleWrite($sUpdateHtml & @CRLF) EndFunc ;============================================================================== ; Note: The regular expression assumes that the search text is case sensitive. ;============================================================================== Func _HTML_ReplaceAllText($sSource, $sSearchText, $sReplaceText) Return StringRegExpReplace($sSource, StringFormat("(>.*?)%s([^=][^<]*)", $sSearchText), "$1" & $sReplaceText & "$2") EndFunc Output: <div><p style="text-align:left;">MODIFIED_STYLE: <span style="float:right;">MODIFIED_CASUAL</span></p></div><div><p style="text-align:left;">MODIFIED_COLOR: <span style="float:right;">Navy Blue</span></p></div><div><p style="text-align:left;">Pattern Type: <span style="float:right;">Plain</span></p></div><div><p style="text-align:left;">Neckline: <span style="float:right;">Round Neck</span></p></div><div><p style="text-align:left;">Length: <span style="float:right;">Long</span></p></div><div><p style="text-align:left;">Type: <span style="float:right;">A Line</span></p></div><div><p style="text-align:left;">Details: <span style="float:right;">Pearls</span></p></div><div><p style="text-align:left;">Details: <span style="float:right;">Frill</span></p></div><div><p style="text-align:left;">Details: <span style="float:right;">Beaded</span></p></div><div><p style="text-align:left;">Details: <span style="float:right;">Pocket</span></p></div><div><p style="text-align:left;">Sleeve Length: <span style="float:right;">Half Sleeve</span></p></div><div><p style="text-align:left;">Season: <span style="float:right;">Spring/Fall</span></p></div><div><p style="text-align:left;">Composition: <span style="float:right;">75% Cotton</span></p></div><div><p style="text-align:left;">Composition: <span style="float:right;">Denim</span></p></div><div><p style="text-align:left;">Composition: <span style="float:right;">25% Polyester</span></p></div><div><p style="text-align:left;">Fabric: <span style="float:right;">Non-Stretch</span></p></div><div><p style="text-align:left;">Waist Line: <span style="float:right;">Natural</span></p></div><br /><table border="1"><thead><tr><th>size</th><th>Shoulder </th><th>Bust </th><th>Waist Size </th><th>Hip Size </th><th>Sleeve Length </th><th>Length </th><th>Bicep Length </th><th>Cuff </th></tr></thead><tbody><tr><td>XS</td><td> 38 cm</td><td> 91 cm</td><td> 90 cm</td><td> 101 cm</td><td> 39 cm</td><td> 139 cm</td><td> 30 cm</td><td> 25 cm</td></tr><tr><td>S</td><td> 39 cm</td><td> 95 cm</td><td> 94 cm</td><td> 105 cm</td><td> 40 cm</td><td> 140 cm</td><td> 31 cm</td><td> 26 cm</td></tr><tr><td>M</td><td> 40 cm</td><td> 99 cm</td><td> 98 cm</td><td> 109 cm</td><td> 41 cm</td><td> 141 cm</td><td> 32 cm</td><td> 27 cm</td></tr><tr><td>L</td><td> 41 cm</td><td> 103 cm</td><td> 102 cm</td><td> 113 cm</td><td> 42 cm</td><td> 142 cm</td><td> 33 cm</td><td> 28 cm</td></tr></tbody></table> @TheXman Wow ! i did a quick test it seems to work, but i don't really understand what is happening here... 😅 can you please explain ? what is StringFormat i tried reading the help but did not quit understood ... also the regex does not sems the match.. what is happening here ? this is way above my skills 😁 AutoFox, A Modern, Simple, No dependency, Noob friendly yet powerful Firefox UDF ! Link to comment Share on other sites More sharing options...
Solution TheXman Posted July 20, 2023 Solution Share Posted July 20, 2023 (edited) 4 hours ago, fraizor said: what is StringFormat Basically, it is a function that allows you to reformat a string based on a given pattern. I used it because, at least for me, it is much easier to read and maintain than writing: "(>.*?)\Q" & $sSearchText & "\E([^=][^<]*)" Using StringFormat for simple strings (like the one above) may be a little overkill, but for more complex strings it makes building the string much easier. I could have used it for the replacement text also but I did it using regular concatenation. 4 hours ago, fraizor said: also the regex does not sems the match If you want to test the regular expressions on regex101.com, then you need to do the string replacement that the script is doing. So for "Style", the pattern would be: "(>.*?)\QStyle\E([^=][^<]*)" See here: https://regex101.com/r/pvrWi1/1 Edited July 20, 2023 by TheXman Added \Q...\E to the regular expression. fraizor and Musashi 2 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
OJBakker Posted July 20, 2023 Share Posted July 20, 2023 Try if search replace with case sensitivity is enough to filter the Style. if StringInStr($DescFile[$i], "Style", $STR_CASESENSE) then $DescFile[$i] = StringReplace($DescFile[$i],"Style",$DictFile[$n][1], 0, $STR_CASESENSE) Endif An other probably more reliable approach is to search those Style NOT followed by an = character. In pseudo-code replace "style=" by placeholder replace remaining "Style" by your replacement replace placeholder by "style=" fraizor 1 Link to comment Share on other sites More sharing options...
fraizor Posted July 20, 2023 Author Share Posted July 20, 2023 24 minutes ago, TheXman said: Basically, it is a function that allows you to reformat a string based on a given pattern. I used it because, at least for me, it is much easier to read and maintain than writing: "(>.*?)" & $sSearchText & "([^=][^<]*)" But for others, the string above is easier for them to use. If you want to test the regular expressions on regex101.com, then you need to do the string replacement that the script is doing. So for "Style", the pattern would be: "(>.*?)Style([^=][^<]*)" See here: https://regex101.com/r/0zIp6L/1 Thank you very much , will take a deeper look into all of these new stuff AutoFox, A Modern, Simple, No dependency, Noob friendly yet powerful Firefox UDF ! Link to comment Share on other sites More sharing options...
TheXman Posted July 20, 2023 Share Posted July 20, 2023 (edited) You're welcome! Edit: @fraizor Please note that I made a small addition to the original regular expression. I added \Q...\E which helps make the expression more robust. Basically, it is used to make sure that the search text is used literally. It only really makes a difference if/when the search text includes characters that are recognized as regular expression characters like: "[", ".", "(", "?", etc. Edited July 20, 2023 by TheXman fraizor 1 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
fraizor Posted July 23, 2023 Author Share Posted July 23, 2023 On 7/20/2023 at 9:09 PM, TheXman said: You're welcome! Edit: @fraizor Please note that I made a small addition to the original regular expression. I added \Q...\E which helps make the expression more robust. Basically, it is used to make sure that the search text is used literally. It only really makes a difference if/when the search text includes characters that are recognized as regular expression characters like: "[", ".", "(", "?", etc. Thank you again how can i make the regex not case sensitive ? i tried this but it does not seems to work Func _HTML_ReplaceAllText($sSource, $sSearchText, $sReplaceText) Return StringRegExpReplace( _ $sSource, _ StringFormat("(?i)(>.*?)\\Q%s\\E([^=][^<]*)", $sSearchText), _ "$1" & $sReplaceText & "$2" _ ) EndFunc AutoFox, A Modern, Simple, No dependency, Noob friendly yet powerful Firefox UDF ! Link to comment Share on other sites More sharing options...
TheXman Posted July 23, 2023 Share Posted July 23, 2023 (edited) I made it case-sensitive for a reason. If it is not case-sensitive, you may change the case of words you did not mean to change. If it is case-sensitive, then the replacement string can be made to match the case of the search string. In any case, your modification to make it case-insensitive works for me. https://regex101.com/r/AJYOL8/1 Edited July 23, 2023 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
mikell Posted July 23, 2023 Share Posted July 23, 2023 May I add, don't double the backslash before Q and E . If you do this, you match the literals "\Q" and "\E" Examples below $s = "ab*cd" $res = StringRegExpReplace($s, '\\Qb*c\\E', "12") ; doesn't work Msgbox(0,"", $res) $res = StringRegExpReplace($s, '\Qb*c\E', "12") Msgbox(0,"", $res) $s = "a\Qbc\Ed" $res = StringRegExpReplace($s, '\\Qbc\\E', "12") ; doesn't work Msgbox(0,"", $res) $res = StringRegExpReplace($s, '\Qbc\E', "12") Msgbox(0,"", $res) Link to comment Share on other sites More sharing options...
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