#1125 closed Bug (Fixed)
StringRegExpReplace fails for case insensitive group (?i...)
| Reported by: | martin | Owned by: | J-Paul Mesnage |
|---|---|---|---|
| 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)
follow-up: 2 comment:1 by , 17 years ago
comment:2 by , 17 years ago
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 , 17 years ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
comment:4 by , 16 years ago
| Milestone: | → 3.3.1.2 |
|---|---|
| Owner: | changed from to |
| Resolution: | → Fixed |
| Status: | assigned → closed |
Fixed in version: 3.3.1.2
comment:5 by , 16 years ago
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.

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