Jump to content

Recommended Posts

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 by Melba23
Not necessarily an AutoIt "bug"
Link to post
Share on other sites

Thanks :o  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 by Guy_
Link to post
Share on other sites
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.

 

Link to post
Share on other sites
  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites

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)

 

Link to post
Share on other sites
42 minutes ago, jguinch said:

the last parenthesis is useless

Wrong, one of the left parenthesis is escaped...

Link to post
Share on other sites

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.

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 here
RegExp tutorial: enough to get started
PCRE 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 post
Share on other sites

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:

0x2000  > <   “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‿<

 

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 here
RegExp tutorial: enough to get started
PCRE 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 post
Share on other sites
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 here
RegExp tutorial: enough to get started
PCRE 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 post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...