Jump to content

Case insensitivity for a group has wrong effect.


 Share

Recommended Posts

I want to replace a parameter in a function and I have tried doing it like this

;the string to change
$str1 = "$gui = GUICreate($OETitle, $GuiWid, $GuiHt, $moepos[0], $moepos[1])"

;Change the 4th parameter
$res2 = StringRegExpReplace($str1,"(\$gui\s*=\s*GUICreate\([^,]*,[^,]*,[^,]*,)([^,]*,)(.*)","$1 800,$3")
ConsoleWrite("Result 1 >" & $res2 & @CRLF);works as I want but only in case is correct

;same change but set case insensitivity for first group
$res2 = StringRegExpReplace($str1,"(?i\$gui\s*=\s*GUICreate\([^,]*,[^,]*,[^,]*,)([^,]*,)(.*)","$1+800,$3");(?i:$gui\s*=\s*guicreate)")
ConsoleWrite("Result 2 >" & $res2 & @CRLF);doesn't work for case insensitivity in first group

I get this result

Result 1 >$gui = GUICreate($OETitle, $GuiWid, $GuiHt, 800, $moepos[1]);<-------understood
Result 2 >$gui = GUICreate($OETitle, $GuiWid, $GuiHt, $moepos[0], $moepos[1]);<-------I don't understand

Am I doing something wrong, misunderstanding the help or does case insensitivity for a group not behave the way it should?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Are you trying to make it case sensitive, or not sensitive?

Edit01: Added below.

Edit02: Changed [autotit] to [autoit ]

Edit03: Changed case of 'g' and it still matches

Try

$res2 = StringRegExpReplace($str1,"(?i)(\$gui\s*=\s*gUICreate\([^,]*,[^,]*,[^,]*,)([^,]*,)(.*)","$1+800,$3");(?i:$gui\s*=\s*guicreate)")

Hope this helps,

Jarvis

Edited by JSThePatriot

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Are you trying to make it case sensitive, or not sensitive?

Edit01: Added below.

Edit02: Changed [autotit] to [autoit ]

Edit03: Changed case of 'g' and it still matches

Try

$res2 = StringRegExpReplace($str1,"(?i)(\$gui\s*=\s*gUICreate\([^,]*,[^,]*,[^,]*,)([^,]*,)(.*)","$1+800,$3");(?i:$gui\s*=\s*guicreate)")

Hope this helps,

Jarvis

No, I'm trying to do case insensitive. From the help

post-3602-12501132362595_thumb.png

It's true I could use (?i) to make the comparison case insenitive from there on, thanks for that. But I would like to understand how I could make one group case insensitive and, as far as I can understand it, it doesn't behave correctly, ie not as the help describes.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Well the only thing you were missing is a space. Try the following line.

$res2 = StringRegExpReplace($str1,"(?i \$gui\s*=\s*gUICreate\([^,]*,[^,]*,[^,]*,)([^,]*,)(.*)","$1+800,$3");(?i:$gui\s*=\s*guicreate)")

I hope that does it for you,

Jarvis

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Well the only thing you were missing is a space. Try the following line.

$res2 = StringRegExpReplace($str1,"(?i \$gui\s*=\s*gUICreate\([^,]*,[^,]*,[^,]*,)([^,]*,)(.*)","$1+800,$3");(?i:$gui\s*=\s*guicreate)")

I hope that does it for you,

Jarvis

Thanks for your effort here Jarvis. Unfortunately it makes no difference. I tried the production and Beta versions.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

What does it output for you? It worked perfectly for me.

;the string to change
$str1 = "$gui = GUICreate($OETitle, $GuiWid, $GuiHt, $moepos[0], $moepos[1])"

;Change the 4th parameter
$res2 = StringRegExpReplace($str1,"(\$gui\s*=\s*GUICreate\([^,]*,[^,]*,[^,]*,)([^,]*,)(.*)","$1 800,$3")
ConsoleWrite("Result 1 >" & $res2 & @CRLF);works as I want but only in case is correct

;same change but set case insensitivity for first group
$res2 = StringRegExpReplace($str1,"(?i \$gui\s*=\s*gUICreate\([^,]*,[^,]*,[^,]*,)([^,]*,)(.*)","$1+800,$3");(?i:$gui\s*=\s*guicreate)")
ConsoleWrite("Result 2 >" & $res2 & @CRLF);doesn't work for case insensitivity in first group

Result 1 >$gui = GUICreate($OETitle, $GuiWid, $GuiHt, 800, $moepos[1])
Result 2 >$gui = GUICreate($OETitle, $GuiWid, $GuiHt, $moepos[0], $moepos[1])

Edit01: Fixed code tag.

Hrm,

Jarvis

Edited by JSThePatriot

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

What does it output for you? It worked perfectly for me.

;the string to change
$str1 = "$gui = GUICreate($OETitle, $GuiWid, $GuiHt, $moepos[0], $moepos[1])"

;Change the 4th parameter
$res2 = StringRegExpReplace($str1,"(\$gui\s*=\s*GUICreate\([^,]*,[^,]*,[^,]*,)([^,]*,)(.*)","$1 800,$3")
ConsoleWrite("Result 1 >" & $res2 & @CRLF);works as I want but only in case is correct

;same change but set case insensitivity for first group
$res2 = StringRegExpReplace($str1,"(?i \$gui\s*=\s*gUICreate\([^,]*,[^,]*,[^,]*,)([^,]*,)(.*)","$1+800,$3");(?i:$gui\s*=\s*guicreate)")
ConsoleWrite("Result 2 >" & $res2 & @CRLF);doesn't work for case insensitivity in first group

Result 1 >$gui = GUICreate($OETitle, $GuiWid, $GuiHt, 800, $moepos[1])
Result 2 >$gui = GUICreate($OETitle, $GuiWid, $GuiHt, $moepos[0], $moepos[1])

Edit01: Fixed code tag.

Hrm,

Jarvis

I am expecting $res2 to be the same as $res1 with 800 replacing $moepos[0] but it doesn't as your result shows. It get the same as you do.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Something is wrong, that's for sure. Most likely the documentation.

If enclosed in brackets all works well. For the group only (I tested only too):

$res2 = StringRegExpReplace($str1,"((?i)\$gui\s*=\s*GUICreate\([^,]*,[^,]*,[^,]*,)([^,]*,)(.*)","$1 800,$3")
ConsoleWrite("Result 2 >" & $res2 & @CRLF)

For all:

$res2 = StringRegExpReplace($str1,"(?i)(\$gui\s*=\s*GUICreate\([^,]*,[^,]*,[^,]*,)([^,]*,)(.*)","$1 800,$3")
ConsoleWrite("Result 2 >" & $res2 & @CRLF)

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

The first one is what he wants. That is definitely a bug. Want to report it Martin since you found it?

Thanks,

Jarvis

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

The first one is what he wants. That is definitely a bug. Want to report it Martin since you found it?

Thanks,

Jarvis

OK.

Ticket #1125

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Something is wrong, that's for sure. Most likely the documentation.

If enclosed in brackets all works well. For the group only (I tested only too):

$res2 = StringRegExpReplace($str1,"((?i)\$gui\s*=\s*GUICreate\([^,]*,[^,]*,[^,]*,)([^,]*,)(.*)","$1 800,$3")
ConsoleWrite("Result 2 >" & $res2 & @CRLF)

For all:

$res2 = StringRegExpReplace($str1,"(?i)(\$gui\s*=\s*GUICreate\([^,]*,[^,]*,[^,]*,)([^,]*,)(.*)","$1 800,$3")
ConsoleWrite("Result 2 >" & $res2 & @CRLF)

That's a good idea to use (?i) within the group; it seems to be a way round. Thanks trancexx.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

That's a good idea to use (?i) within the group; it seems to be a way round. Thanks trancexx.

(?i) is not actually a way round, it is the way to set case-insensitive from that point on, to the right, in my opinion.

(?i: ... )

(?i)

The two patterns from the help file are correctly documented and work correctly.

(?i ... )

This pattern from the help file could be better described. But, is probably referring to this quote from the link in the help file under StringRegExp :-

"(?im-sx), which sets PCRE_CASELESS and PCRE_MULTILINE while unsetting PCRE_DOTALL and PCRE_EXTENDED, is also permitted."

Link to comment
Share on other sites

(?i) is not actually a way round, it is the way to set case-insensitive from that point on, to the right, in my opinion.

I think it does work as trancexx suggested.

$Test = "aBcDeFGHi"
$res1 = StringRegExpReplace($Test,"(?i)(abcd).*(fg)","$1pink");try with case insesitive for all
ConsoleWrite("Result 1 >"  & $res1 & @CRLF)

$res2 = StringRegExpReplace($Test,"((?i)abcd).*(fg)","$1pink");try with case insensitive for first group only
ConsoleWrite("Result 2 >"  & $res2 & @CRLF)

gives

Result 1 >aBcDpinkHi
Result 2 >aBcDeFGHi

which is what is wanted. It also seems logical to me.

I think the easiest fix would be to change the documentation to show this way.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Martin,

Yea I tested trancexx's code, and it does do exactly as you were wishing. He just grouped the case-insensitive ALL within a group, which works, but we expected the other described option to work as described in the help file.

Thanks,

Jarvis

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

After looking over the documentation on PCRE.org, it would seem that Malkey is correct. We'll see how the Developers decide to fix this. They may have added that syntax themselves, or where ever they got their engine from (if not directly from PCRE), then it may have added that small extra in the syntax.

Anyways, glad you got a working solution Martin.

Jarvis

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

In my opinion this is definately not an Autoit a bug, other than possibly with the documentation.or a PCRE bug either for that matter

I've tried the following with several different regular expression engines and get the same results with all

This is not a valid regular expression pattern

"(?i\$gui\s*=\s*guicreate\([^,]*,)(\[^,]*,)(.*)"

This is a valid pattern but as well as making the first group case insensitive it also makes it non-capturing

"(?i:\$gui\s*=\s*guicreate\([^,]*,)(\[^,]*,)(.*)"

This is the correct pattern to achieve what the OP wants

"((?i:\$gui\s*=\s*guicreate\([^,]*,))(\[^,]*,)(.*)"

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

In my opinion this is definately not an Autoit a bug, other than possibly with the documentation.or a PCRE bug either for that matter

I've tried the following with several different regular expression engines and get the same results with all

This is not a valid regular expression pattern

"(?i\$gui\s*=\s*guicreate\([^,]*,)(\[^,]*,)(.*)"

This is a valid pattern but as well as making the first group case insensitive it also makes it non-capturing

"(?i:\$gui\s*=\s*guicreate\([^,]*,)(\[^,]*,)(.*)"

This is the correct pattern to achieve what the OP wants

"((?i:\$gui\s*=\s*guicreate\([^,]*,))(\[^,]*,)(.*)"

LOL, your third expression is yet another way of doing the same thing. I love Regular Expressions... so many ways to skin the same cat.

I agree it seems to be more of a documentation bug not a AutoIt or PCRE bug. The only way this would be different, is if AutoIt added that functionality for itself because it makes sense. If you can do a ?i: then why not simply a ?i so you can capture.

Just my humble opinion,

Jarvis

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

AutoIt use the official PCRE engine so if the doc which has been been from the old time when it was noy using it is incorrect please post what you suggest to change.

as you note so many way to do the same thing does not help to have a simple doc !!!

Link to comment
Share on other sites

I don't see where any of you gurus even bothered trying to play with \E or (?-i).

Experiment people, it's the best way to learn SREs.

M23, I sent you some more links yesterday.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

AutoIt use the official PCRE engine so if the doc which has been been from the old time when it was noy using it is incorrect please post what you suggest to change.

as you note so many way to do the same thing does not help to have a simple doc !!!

The first thing to change is to remove the part of the documentation which says that

(?i...) Case insensitive group. Behaves like a normal group....

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...