Jump to content

StringRegExpReplace() and tagged expressions


Recommended Posts

Hello All,

I am trying to get a tagged expression to work with StringRegExpReplace(), but can't put it together. Is it even possible with the function?

Search for: (?i)\(.*\)test\(.*\)

Replace with: \1NewTest\2

Changing 16test17.txt

To 16NewTest17.txt

and

Changing 16Test17.txt

To 16NewTest17.txt

I need to keep the case-insensitive portion, and this is only a simple example a more complex could be:

Search for: (?i)\(.*\)test\(.*\)\.txt

Replace with: \1NewTest\2.bat

Changing 16test17.txt

To 16NewTest17.bat

If you are using the SciTe text editor, remove the (?i) from the search and you can see this work on the following list:

1test2.txt

2test3.txt

3test4.txt

4test5.txt

5test6.txt

6test7.txt

7test8.txt

8test9.txt

9test10.txt

10test11.txt

11test12.txt

12test13.txt

13test14.txt

14test15.txt

15test16.txt

16test17.txt

test18.txt

test19.txt

Test.txt

Regards,

Karl

Link to comment
Share on other sites

Hello All,

I am trying to get a tagged expression to work with StringRegExpReplace(), but can't put it together. Is it even possible with the function?

Search for: (?i)\(.*\)test\(.*\)

Replace with: \1NewTest\2

Changing 16test17.txt

To 16NewTest17.txt

and

Changing 16Test17.txt

To 16NewTest17.txt

I need to keep the case-insensitive portion, and this is only a simple example a more complex could be:

Search for: (?i)\(.*\)test\(.*\)\.txt

Replace with: \1NewTest\2.bat

Changing 16test17.txt

To 16NewTest17.bat

If you are using the SciTe text editor, remove the (?i) from the search and you can see this work on the following list:

1test2.txt

2test3.txt

3test4.txt

4test5.txt

5test6.txt

6test7.txt

7test8.txt

8test9.txt

9test10.txt

10test11.txt

11test12.txt

12test13.txt

13test14.txt

14test15.txt

15test16.txt

16test17.txt

test18.txt

test19.txt

Test.txt

Regards,

Karl

I couldn't figure out what the extra backslashes were for in your RegExp, so I just removed them, and this seems to work:
Global $avInput[3] = ["1test2.txt", "2test3.txt", "3test4.txt"]

For $n = 0 To UBound($avInput) - 1
    ConsoleWrite("Input: " & $avInput[$n] & @LF)
    ConsoleWrite("Output: " & StringRegExpReplace($avInput[$n], "(?i)(.*)test(.*)", "\1NewTest\2") & @LF)
Next

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

The extra backlsahes were what the text editor uses to tag the expressions. I am not sure what I had when I used your version, which does work. Must have had some typo with that test.

Thank you for the reply!

Karl

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...