Guy_ Posted January 24, 2020 Share Posted January 24, 2020 (edited) I've recently had to reinstall Windows and I guess I updated AutoIt to the current version. I've been using a line of code that has always worked flawlessly and I can't figure out why it's failing now... This normally changes quotes into typographer's quotes, yet it is now dropping off the second quote for some reason... It just vanishes. $Clip = 'Some "nice sample" text.' $Clip = StringRegExpReplace( $Clip, '(?:(?:(?<=^|[^=][^=\w])["“”])([^"“”]+[.,!?\)]?)(?:["”]))', '“$1”') MsgBox(1,"", $Clip) Expected result: Some “nice sample” text. Result: Some “nice sample text. Edited January 25, 2020 by Melba23 Not necessarily an AutoIt "bug" Link to comment Share on other sites More sharing options...
TheXman Posted January 24, 2020 Share Posted January 24, 2020 I get the expected result when I run it. 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...
Guy_ Posted January 24, 2020 Author Share Posted January 24, 2020 (edited) Thanks How strange is that... I get the "bug" both in my actual program and in the separate test, run from SciTE or compiled... I'm still in Win 7 though. You seem to be too? I might try an older AutoIt version. Or otherwise, maybe I have new damage in Windows files... Edited January 25, 2020 by Guy_ Link to comment Share on other sites More sharing options...
TheXman Posted January 25, 2020 Share Posted January 25, 2020 5 hours ago, Guy_ said: I'm still in Win 7 though. You seem to be too? I ran the supplied snippet on both Window 7 & Windows 10, using the latest general release of AutoIt3 (v3.3.14.5), and got the expected results on both OSes. 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...
Marc Posted January 25, 2020 Share Posted January 25, 2020 (edited) Tried on Win10 x64 Strange. At least according to http://regexstorm.net/tester we should get 'Some "nice sample" text.' as result. Edited January 25, 2020 by Marc Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 25, 2020 Moderators Share Posted January 25, 2020 Guy_, I have amended your original thread title for 2 reasons: it is not necessarily an AutoIt bug - and to attract the RegEx gurus who might otherwise miss the thread! M23 Guy_ 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Malkey Posted January 25, 2020 Share Posted January 25, 2020 Using curly brackets around the back-reference number, "${1}", in the replace parameter, appears to return the "Expected result" - for some reason. $Clip = 'Some "nice sample" text.' $Clip = StringRegExpReplace($Clip, '(?:(?:(?<=^|[^=]|[^=\w])["“”])([^"“”]+[.,!?\)]?)(?:["”]))', '“${1}”') ;$Clip = StringRegExpReplace( $Clip, '(?:["“])([^"“”]+)(?:["”])', '“${1}”') ConsoleWrite($Clip & @CRLF) MsgBox(1, "", $Clip) Guy_ and mikell 2 Link to comment Share on other sites More sharing options...
jguinch Posted January 25, 2020 Share Posted January 25, 2020 @Guy_ : It seems that your regex pattern is wrong : the last parenthesis is useless (?:(?:(?<=^|[^=][^=\w])["“”])([^"“”]+[.,!?\)]?)(?:["”]) <= Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Nine Posted January 25, 2020 Share Posted January 25, 2020 42 minutes ago, jguinch said: the last parenthesis is useless Wrong, one of the left parenthesis is escaped... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
jguinch Posted January 25, 2020 Share Posted January 25, 2020 oups... you are right.. Sorry I removed it and it worked... Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
jchd Posted January 25, 2020 Share Posted January 25, 2020 I get the same (surprinsingly wrong) result here (W7 x64 French). I wild guess the OS version is irrelevant but maybe a setting applying to typing correction is the culprit. For instance, the following works: $Clip = 'Some "nice sample" text and another "sample".' $Clip = StringRegExpReplace($Clip, '(["“”])(.*?)(["“”])', '“$2' & ChrW(0x200B) & '”') MsgBox(1, "", $Clip) Removing the ChrW(0x200B) [ZERO WIDTH SPACE] causes the closing ChrW(0x201D) [RIGHT DOUBLE QUOTATION MARK] to vanish in the result. jguinch 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
jguinch Posted January 25, 2020 Share Posted January 25, 2020 $Clip = 'Some "nice sample" text and another "sample".' $Clip = StringRegExpReplace($Clip, '(["“”])(.*?)(?1)', '“${2}”') MsgBox(1, "", $Clip) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
jguinch Posted January 25, 2020 Share Posted January 25, 2020 (edited) same answer than @Malkey Edited January 25, 2020 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
mikell Posted January 25, 2020 Share Posted January 25, 2020 Malkey's answer solved the problem (for me) Link to comment Share on other sites More sharing options...
jguinch Posted January 25, 2020 Share Posted January 25, 2020 (edited) @jchd : excellent ! I didn't know the existence of a zero width character like that ! Edited January 25, 2020 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
jchd Posted January 25, 2020 Share Posted January 25, 2020 It would seem (but take that with a drop of salt) that the numeric part of the group specifiers in the replace part ($1, $2, ... or \1, \2, ...) is handled wrongly. Here's a little test showing that in this Unicode codepoint vincinity (and most probably alsewhere), many codepoints don't get handled correctly when they appear right after the last digit of the group number, but get thru fine elsewhere: $Clip = 'Some "nice sample" text and another "sample".' For $i = 0 To 63 $cw(StringRegExpReplace($Clip, '.*?(["“”])(.*?)(["“”]).*', '0x' & Hex(0x2000 + $i, 4) & @TAB & '>' & ChrW(0x2000 + $i) & '<' & @TAB & '“$2' & ChrW(0x2000 + $i) & '<')) Next $cw() is a homebrew UTF8-aware consolewrite. Output: expandcollapse popup0x2000 > < “nice sample< 0x2001 > < “nice sample < 0x2002 > < “nice sample< 0x2003 > < “nice sample < 0x2004 > < “nice sample< 0x2005 > < “nice sample< 0x2006 > < “nice sample < 0x2007 > < “nice sample < 0x2008 > < “nice sample < 0x2009 > < “nice sample < 0x200A > < “nice sample< 0x200B >< “nice sample< 0x200C >< “nice sample< 0x200D >< “nice sample< 0x200E >< “nice sample< 0x200F >< “nice sample< 0x2010 >‐< “nice sample‐< 0x2011 >‑< “nice sample‑< 0x2012 >‒< “nice sample‒< 0x2013 >–< “nice sample–< 0x2014 >—< “nice sample< 0x2015 >―< “nice sample< 0x2016 >‖< “nice sample‖< 0x2017 >‗< “nice sample‗< 0x2018 >‘< “nice sample‘< 0x2019 >’< “nice sample’< 0x201A >‚< “nice sample‚< 0x201B >‛< “nice sample‛< 0x201C >“< “nice sample< 0x201D >”< “nice sample< 0x201E >„< “nice sample< 0x201F >‟< “nice sample‟< 0x2020 >†< “nice sample< 0x2021 >‡< “nice sample‡< 0x2022 >•< “nice sample< 0x2023 >‣< “nice sample‣< 0x2024 >․< “nice sample< 0x2025 >‥< “nice sample< 0x2026 >…< “nice sample…< 0x2027 >‧< “nice sample‧< 0x2028 > < “nice sample < 0x2029 > < “nice sample < 0x202A >< “nice sample< 0x202B >< “nice sample< 0x202C >< “nice sample< 0x202D >< “nice sample< 0x202E >< “nice sample< 0x202F > < “nice sample < 0x2030 >‰< “nice sample‰< 0x2031 >‱< “nice sample‱< 0x2032 >′< “nice sample< 0x2033 >″< “nice sample″< 0x2034 >‴< “nice sample< 0x2035 >‵< “nice sample< 0x2036 >‶< “nice sample‶< 0x2037 >‷< “nice sample‷< 0x2038 >‸< “nice sample‸< 0x2039 >‹< “nice sample‹< 0x203A >›< “nice sample›< 0x203B >※< “nice sample※< 0x203C >‼< “nice sample< 0x203D >‽< “nice sample< 0x203E >‾< “nice sample< 0x203F >‿< “nice sample‿< Guy_ 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
mikell Posted January 25, 2020 Share Posted January 25, 2020 3 hours ago, jchd said: For instance, the following works But (for me) it doesn't in the OP's example $Clip = 'Some "nice sample" text.' $Clip = StringRegExpReplace( $Clip, '(?:(?:(?<=^|[^=][^=\w])["“”])([^"“”]+[.,!?\)]?)(?:["”]))', '“$1' & ChrW(0x200B) & '”') MsgBox(1,"", $Clip) Link to comment Share on other sites More sharing options...
jchd Posted January 25, 2020 Share Posted January 25, 2020 6 hours ago, Malkey said: Using curly brackets around the back-reference number, "${1}", in the replace parameter, appears to return the "Expected result" - for some reason. I may be wrong but I believe the replace pattern isn't parsed by the PCRE library but by the code in our StringRegExpReplace() function. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Guy_ Posted January 25, 2020 Author Share Posted January 25, 2020 Wow, thank you all for your help and interest! 🙂 "Malkey's braces" fixed it in my main app too. What a relief... Link to comment Share on other sites More sharing options...
Bert Posted January 27, 2020 Share Posted January 27, 2020 If you go to the helpfile and look for "Tutorial - Regular Expression" then when there scrool to the bottom, you will see a button called "Open StringRegExpGUI.au3" click it and then run the script from SciTE. You will get this tool: Guy_ 1 The Vollatran project My blog: http://www.vollysinterestingshit.com/ 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