ccbamatx Posted May 11, 2016 Share Posted May 11, 2016 I am having some trouble with StringRegExpReplace Can someone show me how to replace the following in a text string data data data data data data data data data CRLF data data data data data data data data data CRLF STARTING TEXT TAG data data data data data data data data data CRLF data data data data data data data data data CRLF 01010101010101010101010101010101010101 CRLF ENDING TEXT TAG data data data data data data data data data CRLF data data data data data data data data data CRLF I want to replace, starting with STARTING TEXT TAG... including the variable length data in between with CRLFs and ending with ENDING TEXT TAG with "" I can get STARTING {something} TAG with (?i)STARTING(.*?)TAG ...but I cant figure out how to get the other lines of data. Thanks a lot Link to comment Share on other sites More sharing options...
JeremyNicoll Posted May 11, 2016 Share Posted May 11, 2016 Personally, in any programming language, I'd use StringInStr to find where "STARTING TEXT TAG" is, then search forward from there using StringInStr again to find the position of the ENDING TEXT TAG. Then I'd join together the part of the string that was before the first tag and the bit after the end tag. Using anything regex based is potentially very wasteful of cpu time, especially if the text being searched is very large or (if one's using a much more complicated regex pattern) if the regex search algorithm has a lot of work to find the precise part of the text that matches the conditions you code. Link to comment Share on other sites More sharing options...
mikell Posted May 11, 2016 Share Posted May 11, 2016 This works with the provided test string. Obviously this could not work with the real (not provided) string $str = "data1 data1 data1" & @CRLF & _ "data1 data1 data1" & @CRLF & _ "STARTING TEXT TAG" & @CRLF & _ "data2 data2 data2" & @CRLF & _ "data2 data2 data2" & @CRLF & _ @CRLF & _ "01010101010101010101010101010101010101" & @CRLF & _ "ENDING TEXT TAG" & @CRLF & _ "data3 data3 data3" & @CRLF & _ "data3 data3 data3" & @CRLF msgbox(0,"", $str) $str = StringRegExpReplace($str, '(?s)STARTING TEXT TAG.*?ENDING TEXT TAG\R?', "") msgbox(0,"", $str) ccbamatx 1 Link to comment Share on other sites More sharing options...
ccbamatx Posted May 11, 2016 Author Share Posted May 11, 2016 Perfect!!! 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