Modify

#1125 closed Bug (Fixed)

StringRegExpReplace fails for case insensitive group (?i...)

Reported by: martin Owned by: Jpm
Milestone: 3.3.1.2 Component: AutoIt
Version: 3.3.0.0 Severity: None
Keywords: StringRegExpReplace Case Insensitive Group Cc:

Description

This example

;replace the 2nd parameter using case insensitivity for the whole match
$res1 = StringRegExpReplace("$gui = GuiCreate($a,$b,$c)","(?i)(\$gui\s*=\s*guicreate\([^,]*,)([^,]*,)(.*)","$1 800,$3")
ConsoleWrite("Result 1 >" & $res1 & @CRLF)

;same change but set case insensitivity for first group only, should give same result
$res2 = StringRegExpReplace("$gui = GuiCreate($a,$b,$c)","(?i\$gui\s*=\s*guicreate\([^,]*,)([^,]*,)(.*)","$1 800,$3")
ConsoleWrite("Result 2 >" & $res2 & @CRLF)

gives this result

Result 1 >$gui = GuiCreate($a, 800,$c)
Result 2 >$gui = GuiCreate($a,$b,$c)

I think Result 2 should be the same as result 1.

Discussed http://www.autoitscript.com/forum/index.php?showtopic=100147&view=findpost&p=716575.

Attachments (0)

Change History (5)

comment:1 by Jpm, on Aug 14, 2009 at 7:22:53 AM

please post what is wrong in the doc if any and how you suggest to fix it

in reply to:  1 comment:2 by Valik, on Aug 14, 2009 at 3:50:17 PM

Replying to Jpm:

please post what is wrong in the doc if any and how you suggest to fix it

I don't know that it is a documentation issue. I expect the same results martin expects. I can see no reason the pattern would behave differently. This needs more investigation to ensure there's not a PCRE bug or a bug in our implementation.

comment:3 by Jpm, on Aug 15, 2009 at 6:42:17 AM

Owner: set to Valik
Status: newassigned

comment:4 by Jpm, on Oct 12, 2009 at 10:24:09 AM

Milestone: 3.3.1.2
Owner: changed from Valik to Jpm
Resolution: Fixed
Status: assignedclosed

Fixed in version: 3.3.1.2

comment:5 by Valik, on Oct 14, 2009 at 3:20:33 AM

Since JP didn't see fit to explain this, I will. Case-sensitive and case-insensitive groups are not supported with the syntax demonstrated above. Instead, the (?i) option specifier has the following behavior according to the PCRE documentation (this section specifically):

When an option change occurs at top level (that is, not inside subpattern parentheses), the change applies to the remainder of the pattern that follows. If the change is placed right at the start of a pattern, PCRE extracts it into the global options (and it will therefore show up in data extracted by the pcre_fullinfo() function).

An option change within a subpattern affects only that part of the current pattern that follows it, so

Thus, to fix the pattern from martin, it would be:

;replace the 2nd parameter using case insensitivity for the whole match
$res1 = StringRegExpReplace("$gui = GuiCreate($a,$b,$c)","(?i)(\$gui\s*=\s*guicreate\([^,]*,)([^,]*,)(.*)","$1 800,$3")
ConsoleWrite("Result 1 >" & $res1 & @CRLF)

;same change but set case insensitivity for first group only, should give same result
$res2 = StringRegExpReplace("$gui = GuiCreate($a,$b,$c)","((?i)\$gui\s*=\s*guicreate\([^,]*,)([^,]*,)(.*)","$1 800,$3")
ConsoleWrite("Result 2 >" & $res2 & @CRLF)

Notice that the second pattern contains a (?i) inside the first group. This ensures only the first group is case-insensitive. When that group ends the global behavior is restored (in this case the global behavior is case-sensitive).

The "Fixed" resolution is misleading. The only thing fixed was the documentation no longer shows the invalid option specifiers.

Modify Ticket

Action
as closed The owner will remain Jpm.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.