Jump to content

StringRegExpRelace / Selective match


Recommended Posts

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

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...