Modify

Opened 16 years ago

Closed 16 years ago

#1017 closed Feature Request (Completed)

StringRegExpReplace - back-references --> add this as example in Helpfile

Reported by: Zedna Owned by: Jpm
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 Changed 16 years ago by Valik

That example is far too complex.

comment:2 Changed 16 years ago by Zedna

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 Changed 16 years ago by Zedna

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 Changed 16 years ago by Zedna

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

  • Milestone set to 3.3.1.1
  • Owner set to Jpm
  • Resolution set to Completed
  • Status changed from new to closed

Added in version: 3.3.1.1

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.