Opened 17 years ago
Closed 17 years ago
#1017 closed Feature Request (Completed)
StringRegExpReplace - back-references --> add this as example in Helpfile
| Reported by: | Zedna | Owned by: | J-Paul Mesnage |
|---|---|---|---|
| Milestone: | 3.3.1.1 | Component: | Documentation |
| Version: | Severity: | None | |
| Keywords: | Cc: |
Description
According to this my post:
http://www.autoitscript.com/forum/index.php?s=&showtopic=96512&view=findpost&p=693808
There is no example in HelpFile for StringRegExpReplace - back-references.
So this may be added:
$text_in = _
'some text1 12/31/2009 01:02:03 some text2' & @CRLF & _
'some text3 02/28/2009 11:22:33 some text4'
; change date format from mm/dd/yyyy to dd.mm.yyyy
$text_out = StringRegExpReplace($text_in, '\x20(\d{2})/(\d{2})/(\d{4})\x20', ' $2.$1.$3 ')
MsgBox(0, "RegExp Replace Test - back-references", 'OLD:' & @CRLF & $text_in & @CRLF & @CRLF & 'NEW:' & @CRLF & $text_out )
Output:
OLD: some text1 12/31/2009 01:02:03 some text2 some text3 02/28/2009 11:22:33 some text4 NEW: some text1 31.12.2009 01:02:03 some text2 some text3 28.02.2009 11:22:33 some text4
; comments
#cs
\x20 is Chr(32) ie. space at begin and end of date
each part of date is closed in group ()
each group can be back referenced by $n starting from 1 so '$2.$1.$3' means changed order of MM and DD and using dot instead of slash among date parts
#ce
Attachments (0)
Change History (5)
comment:1 by , 17 years ago
comment:2 by , 17 years ago
That example is far too complex.
I'm curious because there are more complicated ones in the helpfile already.
OK. So here is lightweighted version :-)
$in = 'text1 12/31/2009 01:02:03 text2'
; change date format from mm/dd/yyyy to dd.mm.yyyy
$out = StringRegExpReplace($in, '\x20(\d{2})/(\d{2})/(\d{4})\x20', ' $2.$1.$3 ')
MsgBox(0, "RegExp back-references", $out)
comment:3 by , 17 years ago
Or even simpler one:
$in = '12/31/2009'
; change date format from mm/dd/yyyy to dd.mm.yyyy
$out = StringRegExpReplace($in, '(\d{2})/(\d{2})/(\d{4})', '$2.$1.$3')
MsgBox(0, "RegExp back-references", $out)
comment:4 by , 17 years ago
And winner is:
; change date format from mm/dd/yyyy to dd.mm.yyyy
$out = StringRegExpReplace('12/31/2009', '(\d{2})/(\d{2})/(\d{4})', '$2.$1.$3')
MsgBox(0, "RegExp back-references", $out)
:-)
comment:5 by , 17 years ago
| Milestone: | → 3.3.1.1 |
|---|---|
| Owner: | set to |
| Resolution: | → Completed |
| Status: | new → closed |
Added in version: 3.3.1.1

That example is far too complex.