Author Topic: Brief multi-line regex not working  (Read 3611 times)

StephenW

  • Senior Community Member
  • Posts: 197
  • Hero Points: 21
Brief multi-line regex not working
« on: October 11, 2007, 02:26:11 am »
To reproduce this problem, copy the following lines into the Regex Evaluator tool:

L2 P03 PT00 AT00R  SLV00I SA00 PS01 :: {04}BQ{05} - {04} EV_RPL=10 =>PTFF...
L2... EV_PT=10 =>AT00R  =>PT00 EV_AT=01 =>PT00 EV_SL=00
L2 P04 PT00 AT00R  SLV00I SA00 PS01 :: {04}CQ{05} - {04} EV_RPL=10 =>PTFF...
L2... EV_PT=10 =>AT00R  =>PT00 EV_AT=01 =>PT00 EV_SL=00
L2 P05 PT00  poll reply timeout ...
L2 P05 PT00 AT00R  SLV00I SA00 PS01 :: {04}DQ{05} - EV_RPL=00 =>PTFF...
L2... EV_PT=02 =>PT00 EV_AT=01 =>PT00 EV_SL=00
L2 P06 PT00 AT00R  SLV00I SA00 PS01 :: {04}EQ{05} - {04} EV_RPL=10 =>PTFF...
L2... EV_PT=10 =>AT00R  =>PT00 EV_AT=01 =>PT00 EV_SL=00
L2 P07 PT00 AT00R  SLV00I SA00 PS01 :: {04}FQ{05} - {04} EV_RPL=10 =>PTFF...
L2... EV_PT=10 =>AT00R  =>PT00 EV_AT=01 =>PT00 EV_SL=00
L2 P08 PT00 AT00R  SLV00I SA00 PS01 :: {04}GQ{05} - {04} EV_RPL=10 =>PTFF...
L2... EV_PT=10 =>AT00R  =>PT00 EV_AT=01 =>PT00 EV_SL=00
L2 P09 PT00 AT00R  SLV00I SA00 PS01 :: {04}HQ{05} - {04} EV_RPL=10 =>PTFF...
L2... EV_PT=10 =>AT00R  =>PT00 EV_AT=01 =>PT00 EV_SL=00
L2 P0A PT00 AT00R  SLV00I SA00 PS01 :: {04}IQ{05} - {04} EV_RPL=10 =>PTFF...
L2... EV_PT=10 =>AT00R  =>PT00 EV_AT=01 =>PT00 EV_SL=00
** 27-11:10:34 **

L2 P01 PT03 AT01R  SLV00I SA00 PS01 :: {04}@A{05} - {10}0 EV_RPL=11 =>PT04...
L2... EV_PT=00 EV_AT=00 EV_SL=00
L2 P01 PT04 AT01R  SLV00I SA00 PSFF :: =>PSFF {02}@A15{03}{06} - {10}1...
L2... EV_RPL=12 =>PTFF EV_PT=14 =>AT00R  =>PT00 EV_AT=01 =>PT00 EV_SL=00
L2 P02 PT00 AT00R  SLV00I SA00 PS01 :: {04}AQ{05} - {04} EV_RPL=10 =>PTFF...
L2... EV_PT=10 =>AT00R  =>PT00 EV_AT=01 =>PT00 EV_SL=00
L2 P03 PT00 AT00R  SLV00I SA00 PS01 :: {04}BQ{05} - {04} EV_RPL=10 =>PTFF...
L2... EV_PT=10 =>AT00R  =>PT00 EV_AT=01 =>PT00 EV_SL=00
L2 P04 PT00 AT00R  SLV00I SA00 PS01 :: {04}CQ{05} - {04} EV_RPL=10 =>PTFF...
L2... EV_PT=10 =>AT00R  =>PT00 EV_AT=01 =>PT00 EV_SL=00

Then select SlickEdit regular expressions and use the following as the regular expression (without the quotes): "...\n".  You should see matches at the end of lines, approximately every second line.  Switch to Brief regular expressions - there should be no change as the regular expression is the same in both SlickEdit and Brief syntax.  Switch back to SlickEdit regular expressions, and turn on the Multi-line mode option.  Again, there should be no change.  Turn off Multi-line mode, switch to Brief.  No change.  Turn on Multi-line mode - and now there are no matches.

Lee

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1299
  • Hero Points: 130
Re: Brief multi-line regex not working
« Reply #1 on: October 11, 2007, 01:23:13 pm »
I've confirmed the issue, and I've discovered a minor issue with parsing Brief regex tokens.  When using Brief syntax, it's doing case-sensitive check for \OM and \OL tokens (toggle multi-line matching on/off) when it shouldn't be.  This will be fixed for 2008 release.  In the meantime, this is pretty easy to workaround.  In the macros directory, open tbregex.e and goto line 133, and you'll see where the multi-line match toggle is inserted into the search string.  Change the \om to uppercase, so it should read:

Code: [Select]
   // Make sure the expression contains the \om specification
   // The user may have already specified it in the expression itself
   // If not, tack it on the front. We don't actually modify the user's
   // text in the expression window.
   if(asMultiline)
   {
      if(pos('\om', expressionToTest) == 0)
            expressionToTest = '\OM' :+ expressionToTest;
   }

Reload the module (Macro > Load Module...) and you're good to go.  Thanks for providing an excellent example and steps to reproduce the problem.

StephenW

  • Senior Community Member
  • Posts: 197
  • Hero Points: 21
Re: Brief multi-line regex not working
« Reply #2 on: October 11, 2007, 08:56:16 pm »
So if I am manually using \OM or \OL in a Brief regex, I need to do them in upper case too?  If so, that would explain why \OM has not worked on occasion when I have been trying to use it.

Modifying tbregex.e brings up a problem that I have been running across recently.  I also have a modified seldisp.e, where hs2 was kind enough to provide me with a fix for the selective display GUI not using my default of Brief regular expressions.  I have been keeping the modified seldisp.e in my "custom" directory alongside my own macros, so that it will not be overwritten by a hotfix or an update installation.  Each time I do a hotfix, I have to manually check if there was a change made in seldisp.e, and if so, merge it, and then reload my modified seldisp.e.  I hope eventually that the fixes will be done in the original too, in this case (and now for tbregex.e), but I am sure at some point I will be making changes that will be personal to me and will never be becoming part of the released version.  So I would like to propose that there be a mechanism to handle this situation when hotfixes and updates are applied.  There are probably a number of ways of doing it, but the one that sprang to mind was to have the update process check the first line of each of the macro files it is updating, to see if there is a comment saying:

  /*:: Customised */

or for those of us who speak American English:

  /*:: Customized. */

If so, it would create a backup copy of the .e file as .e.custom before it updated to the new version of the file.  At the end of the hotfix or update process it would pop up a list of all such files it found, preferably in a format that could then be directly used to diff all the files on the list and do merging.  It would be nice if it also created a .e.release file as a copy of the newly installed updated .e file, so that the release version was always available for comparison without my having to copy it manually.

hs2

  • Senior Community Member
  • Posts: 2752
  • Hero Points: 291
Re: Brief multi-line regex not working
« Reply #3 on: October 11, 2007, 09:42:19 pm »
Hence my adopted fix looks like that but it only 'helps' when using the regex evaluator...
Code: [Select]
   if(asMultiline)
   {
      if(pos('\om', expressionToTest) == 0)
            expressionToTest = '\om' :+ expressionToTest;

      // HS2-CHG: WA from Lee - http://community.slickedit.com/index.php?topic=2213.msg9188#msg9188
      //          -> Brief regex bug: req. case sens. '\OM' resp. '\OL' tokens
      expressionToTest = stranslate ( expressionToTest, '\OM', '\om' );
      expressionToTest = stranslate ( expressionToTest, '\OL', '\ol' );
   }

I like your proposal with the customized marker. It would make the upgrade process a bit saver also for me (although I'm carefully backing up all my customizations like you).
Hotfixes are not a big deal b/c it's easy to spot/merge the changes.
Upgrades are always a challenge and I really try hard to avoid any changes in product modules ;)

HS2

Lee

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1299
  • Hero Points: 130
Re: Brief multi-line regex not working
« Reply #4 on: October 11, 2007, 09:53:04 pm »
Quote
So if I am manually using \OM or \OL in a Brief regex, I need to do them in upper case too?  If so, that would explain why \OM has not worked on occasion when I have been trying to use it.

Yep, if you are using Brief syntax you will need to use the uppercase version for it to work correctly.  This will be fixed in the 2008 release.

And, we definitely understand the effort it takes to maintain user modifications with each release.  It something that gets brought up every release cycle, so we would love to hear more suggestions to handle this better.