Antiec Posted May 21, 2008 Posted May 21, 2008 Hi! I'm trying to replace some text in a string and I managed to make it work, but it's a bit weird. Why does the following function replace "test name=" too? Should it? How to format the regexp so it won't replace it? $1 has "test_5" so shouldn't it replace only that part? $name = "dummy_" for $i = 0 to 10 $strtest = StringRegExpReplace( 'test name="dummy_5"', 'test name="(.*)"', $name & $i ) MsgBox( 0, "Test", $strtest ) Next Ofcourse $strtest = StringRegExpReplace( 'test name="dummy_5"', 'test name="(.*)"', 'test name="' & $name & $i & '"' ) works but isn't as neat =/ Sorry for the typos
weaponx Posted May 21, 2008 Posted May 21, 2008 Maybe this? $string = 'test name="dummy_5"' $name = "dummy_" for $i = 0 to 10 $strtest = StringRegExpReplace($string, '(test name=")(.*)(")', "$1" & $name & $i & "$3" ) ConsoleWrite($strtest & @CRLF) Next
Antiec Posted May 22, 2008 Author Posted May 22, 2008 Thx, it does make a bit neater and taught me a bit about regexp syntax. I had a second problem too, but managed to fix it. I'd just like to know is it normal too and why. It's kinda weird... If I use this one, it will result in 'to port=" />' MsgBox( 0, "Test", StringRegExpReplace( '< to port="500" />', '(to port=)(.*)(" />)', "$1" & 6000 & "$3" ) ) But if I add the " quotation it does work. It seems to be the same always if I want to replace with numbers. MsgBox( 0, "Test", StringRegExpReplace( '< to port="500" />', '(to port=)(.*)(" />)', "$1" & '"' & 6000 & "$3" ) )
weaponx Posted May 22, 2008 Posted May 22, 2008 MsgBox( 0, "Test", StringRegExpReplace( '< to port="500" />', '(")(.*)(")', '"' & 6000 & '"') )
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now