Jump to content

Recommended Posts

Posted

In v3.2.1.8, the StringRegExpReplace documentation states "$0 - $9) can be used as back-references". However, when I run this script, I get an undeclared variable error:

MsgBox(0, "Regular Expression Replace Test", StringRegExpReplace("Where have all the flowers gone, long time passing?", "([aeiou])", $0))

Also, shouldn't that statement be $1-$9 can be used as backreferences? Does it truly start at 0?

Who else would I be?
Posted (edited)

John, does this mean that backreference variables are not actually variables? Example:

MsgBox(0, "Regular Expression Replace Test", StringRegExpReplace("Where have all the flowers gone, long time passing?", "([aeiou])", Asc("$0")))

This does not return the ascii code of the backreferenced variable...

This is actually the same as Asc("$").

Edited by this-is-me
Who else would I be?
  • Administrators
Posted

No they are not variables, they are strings. The "replacement" parameter is a string.


 

  • Administrators
Posted

Example:

MsgBox(0, "", StringRegExpReplace("April 15, 2003", "(\w+) (\d+), (\d+)", "$1 1st, $3"))


 

Posted (edited)

I understand this in regards to the \0-\9 strings, but can you give me an example of what to do if I need to make changes to the replacement string? I specifically want to change all numbers into their ascii equivalents if they are between beginning and ending tags.

In short, I need to edit the replacement data where the replacement data is also the data being found by StringRegExp.

Edited by this-is-me
Who else would I be?
  • Administrators
Posted

I understand this in regards to the \0-\9 strings, but can you give me an example of what to do if I need to make changes to the replacement string? I specifically want to change all numbers into their ascii equivalents if they are between beginning and ending tags.

In short, I need to edit the replacement data where the replacement data is also the data being found by StringRegExp.

No idea. Sounds like you want to edit the data that a back reference contains - don't think that's possible.


 

Posted

Would it be possible to make the backreferences available to a macro? I can see great possibilities if the backreference can be edited before replacement.

Who else would I be?
  • Moderators
Posted

If you want to modify what is between two tags, just split the string, process the middle, and put it back together. It's a solution.

StringBetween() or _SRE_Between() does this, well you have to make the UDF to combine it, but they retrieve the inbetween marker strings.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...