youtuber Posted March 17, 2021 Share Posted March 17, 2021 https://regex101.com/r/8E2MuB/1 As you can see here, there is no problem with matching, but when StringRegExpReplace is applied all matches are incorrect. Here I want to change the 6-digit value in the CODE2 tag. $str = "<$test.123456> ;;CODE1" & @CRLF & _ "<$test.123456> ;;CODE2" & @CRLF & _ "<$test.123456> ;;CODE3" ConsoleWrite(StringRegExpReplace($str, "([^<])?\$test\.(\d{6})[(^>)]\h;;CODE2", "000000") & @CRLF) ConsoleWrite(StringRegExpReplace($str, "([^<])?\$test\.(\d{6})([^>])\h;;CODE2", "000000") & @CRLF) ConsoleWrite(StringRegExpReplace($str, "<\$test\.(\d{6})>(?=\h;;CODE2)", "000000") & @CRLF) Link to comment Share on other sites More sharing options...
Developers Jos Posted March 17, 2021 Developers Share Posted March 17, 2021 You mean something like this?: ConsoleWrite(StringRegExpReplace($str, "(<\$test)\.\d{6}(>\h;;CODE2)", "$1.000000$2") & @CRLF& @CRLF) youtuber 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
youtuber Posted March 17, 2021 Author Share Posted March 17, 2021 Yes that's what I want, but can I add a variable there? $var = "000000" ConsoleWrite(StringRegExpReplace($str, "(<\$test)\.\d{6}(>\h;;CODE2)", "$1.$var$2") & @CRLF& @CRLF) Link to comment Share on other sites More sharing options...
Developers Jos Posted March 17, 2021 Developers Share Posted March 17, 2021 1 minute ago, youtuber said: Yes that's what I want, but can I add a variable there? You really need to think about these things a little longer! You want to concatenate the content of that variable into the result string! Something like this? $var = "000000" ConsoleWrite(StringRegExpReplace($str, "(<\$test)\.\d{6}(>\h;;CODE2)", "$1." & $var & "$2") & @CRLF & @CRLF) "Jos youtuber 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
youtuber Posted March 17, 2021 Author Share Posted March 17, 2021 Oh yes I never thought of separating the variable, sorry Thank you I want to use your jos pattern for StringRegExp too. Is there a solution for that too? Sample: #include <array.au3> $str = "<$test.123456> ;;CODE1" & @CRLF & _ "<$test.123456> ;;CODE2" & @CRLF & _ "<$test.123456> ;;CODE3" $RegExp = StringRegExp($str, "(<\$test\.)\d{6}(>\h;;CODE2)",3) If IsArray($RegExp) Then _ArrayDisplay($RegExp) EndIf https://regex101.com/r/BR75fa/1 Group 1 <$test. Group 2 > ;;CODE2 It would be nice to get that 6-digit number from the previous and next grouping Link to comment Share on other sites More sharing options...
Developers Jos Posted March 17, 2021 Developers Share Posted March 17, 2021 Put in brackets what you want to capture! Your regex101 clearly shows what you are capturing. youtuber 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
youtuber Posted March 17, 2021 Author Share Posted March 17, 2021 5 minutes ago, Jos said: Put in brackets what you want to capture! Your regex101 clearly shows what you are capturing. yes i think i made it thanks StringRegExp($str, "(?:<\$test)\.(\d{6})(?:>\h;;CODE2)",3) Link to comment Share on other sites More sharing options...
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