HurleyShanabarger Posted September 18, 2020 Share Posted September 18, 2020 I am currently trying to do some code refactoring using regular expressions. If boThis Then // Remove this boThat := TRUE; // Keep this boThere := boSome OR // Remove this boThing; // Remove this EndIf Basically I want to remove comments, whenever the assignment operator := and the colon is not in the line. $_lv_sData = '' $_lv_sData &= 'If boThis Then // Remove this' & @CRLF $_lv_sData &= ' boThat := TRUE; // Keep this' & @CRLF $_lv_sData &= ' boThere := boSome OR // Remove this' & @CRLF $_lv_sData &= ' boThing; // Remove this' & @CRLF $_lv_sData &= 'EndIf' & @CRLF $_lv_sRslt = StringRegExpReplace($_lv_sData, "(?m)^([^;]+)(//.*)$", "$1", 0) MsgBox(0,"", $_lv_sRslt) How do I add the assignment operator := into the regular expression? Thanks a lot! Link to comment Share on other sites More sharing options...
jguinch Posted September 18, 2020 Share Posted September 18, 2020 Ca you try this one ? $_lv_sRslt = StringRegExpReplace($_lv_sData, "(?m)^(?:.+:=[^;]+\K\/\/\V+|[^:]+\K\/\/\V+)", "") HurleyShanabarger 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
mikell Posted September 19, 2020 Share Posted September 19, 2020 11 hours ago, HurleyShanabarger said: whenever the assignment operator := and the colon is not in the line So... just skip this line $_lv_sRslt = StringRegExpReplace($_lv_sData, "(?m)^.+:=.+;.*(*SKIP)(*F)|//\V+", "") jguinch 1 Link to comment Share on other sites More sharing options...
HurleyShanabarger Posted September 19, 2020 Author Share Posted September 19, 2020 1 hour ago, mikell said: So... just skip this line $_lv_sRslt = StringRegExpReplace($_lv_sData, "(?m)^.+:=.+;.*(*SKIP)(*F)|//\V+", "") Holy moly, a whole new world just appeared for me 😄 Link to comment Share on other sites More sharing options...
mikell Posted September 19, 2020 Share Posted September 19, 2020 Yep suggested reading : this Please note that in this case \K could be used instead of (*SKIP)(*FAIL) 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