Modify

Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#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 follow-up: Changed 15 years ago by Jpm

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

comment:2 in reply to: ↑ 1 Changed 15 years ago by Valik

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 Changed 15 years ago by Jpm

  • Owner set to Valik
  • Status changed from new to assigned

comment:4 Changed 15 years ago by Jpm

  • Milestone set to 3.3.1.2
  • Owner changed from Valik to Jpm
  • Resolution set to Fixed
  • Status changed from assigned to closed

Fixed in version: 3.3.1.2

comment:5 Changed 15 years ago by Valik

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.

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain Jpm.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.