Menu

#264 FR: Allow adding CR/LF characters in replacement strings

Next_Release
closed
None
1
2024-04-28
2023-06-04
No

In regex and literal replacement strings it would be most useful to allow CR (ASCII decimal 13) and LF (ASCII decimal 10) characters.

Discussion

  • Morten MacFly

    Morten MacFly - 2023-06-23
    • status: open --> pending
    • Group: Future_Release --> Invalid
    • Priority (9=hightest): 4 --> 1
     
  • Morten MacFly

    Morten MacFly - 2023-06-23

    What would be the use-case? For RegEx, you have a special character for linefeed(s) you can use. You can use RegEx for search/replace and ignore. Therefore, in the case you need a linefeed you should not use the from/to but the RegEx option. Line-feeds would need to be escaped which is error-prone. So unless its really needed and there is no work-around I would not want to to implement this. Keep in mind: You can ignore white-spaces which removes extensive CR-LF usage. This might also be of help.

    But maybe you come up with a use-case first for me to understand...

     
    • Gitoffthelawn

      Gitoffthelawn - 2023-07-23

      Yes, using regex is preferred.

      But how does one specify CR or LF in regex replacement strings in WCM? The normal regex \r and \n do not seem to work. When those are used as replacement strings in WCM, you just get the letters r and n.

      I also tried \\r and \\n, but those replace with the literals (\r and \n) as expected.

      How does one specify CR or LF in regex replacement strings in WCM?

       
  • Gitoffthelawn

    Gitoffthelawn - 2023-07-23

    Note that I'm using the Advanced regex flavour.

    I also tried \x00c in the regex replacement string, but WCM outputs x00c instead of hex char 00C (carriage return).

     

    Last edit: Gitoffthelawn 2023-07-23
  • Morten MacFly

    Morten MacFly - 2023-08-03

    OK, it seems that you need to set a special flag for the RegEx library to work with linefeeds. That flag ("Support EOL") is now exposed to the configuration (UI). Please try again. (Implemented in SVN [r1656]).

     

    Related

    Commit: [r1656]

  • Morten MacFly

    Morten MacFly - 2023-08-03
    • status: pending --> closed
    • Group: Invalid --> Next_Release
     
  • Gitoffthelawn

    Gitoffthelawn - 2023-08-21

    How much did you test this?

    When I try using \n in regex replacement strings, it does not work.

    For example, I had the following literal replacement item (which did not work):

    Type195=1
    From195=</item>
    To195=</item>\\n\\n
    Keep195=0
    RegEx195=
    RegExReplace195=
    CaseSensitive195=1
    Groups195=BETA
    

    I then used WCM to convert that replacement from a literal string replacement to a regex replacement. To do so, I went to the regex tab for the replacement item, and entered </item> in the RegEx to replace and </item>\n\n in the ...with field in that same tab.

    This does not result in newlines being added to the replacement string, as it should.

    It also has the very detrimental effect of causing ALL ignores/replaces after # 194 to disappear from the WCM UI after WCM is closed and reopened.

    Within the settings file, WCM causes the replacement item to now appears as:

    Type195=1
    From195=</item>
    To195=</item>\\n\\n
    Keep195=0
    RegEx195=</item>
    RegExReplace195=</item>\\n\\n
    CaseSensitive195=0
    Groups195=BETA
    
     
    • Morten MacFly

      Morten MacFly - 2023-08-27

      I don't have a test-case so all I do is providing access to the options of the underlying RegEx lib. I've implemented a RegEx testbed no which will be available with the next release. There, you can test yourself how to setup things for you. If you can't manage to do what you want there, then this is a limitation of the RegEx library itself which I cannot fix.

       
    • Morten MacFly

      Morten MacFly - 2023-08-27

      Type195=1
      From195=
      To195=\n\n
      Keep195=0
      RegEx195=
      RegExReplace195=\n\n
      CaseSensitive195=0
      Groups195=BETA

      This should be fixed in SVN now. It happens if you change the type of an ignore.

       
      • Gitoffthelawn

        Gitoffthelawn - 2024-04-28

        Can you please verify this is working for you in v24.04? It's not working for me.

        When I perform a regex replace with \n\n, WCM replaces the matched string with nn.

        BTW, the example you provided looks invalid. Both From195= and RegEx195= are empty, which WCM does not allow. But perhaps you redacted test strings before posting?

         

Log in to post a comment.

MongoDB Logo MongoDB