Forum Discussion

Mez's avatar
Mez
Qrew Captain
2 months ago
Solved

Using RegexReplace()

Does this function support capturing groups, and if yes, how does one access the captured data? 

Intent is to use a this function looking for punctuation from a text field, and then add a new line to this. 

regex: ([.!?])\s*

substitution: $1\n

Documentation doesn't state one way or the other. I've tried escaping the new line value without success. Perhaps I'm just missing something simple. 

  • Found the solution: capturing is referred to with backslash 1, which needs to be escaped. 

    RegexReplace( [Additional Notes], "([.!?])\\s*", "\\1\n" )

     

4 Replies

  • Can you give an example of the before and after results you are looking for?

    • Mez's avatar
      Mez
      Qrew Captain

      Sure. If capturing is supported for this formula, I would like, rather expect that we could invoke the variable nomenclature of $1 to refer to it. It does not appear to be supported. 

      Since the substitution or replace input is a string and you have to escape certain characters I tried "\\n" to  create a newline - no luck; tried to refer to the capture variable - $1 - highlights as yellow - not supported

      RegexReplace( [Notes text], "([.!?])\\s*", $1&"\\n")

      Looks like this might be an enhancement request. 

      *edit: for some reason the solution isn't showing in the thread; posting here. Access captured data with \1, which has to be escaped. 

      RegexReplace( [Notes text], "([.!?])\\s*", "\\1\n")

       

      • Mez's avatar
        Mez
        Qrew Captain

        Found the solution: capturing is referred to with backslash 1, which needs to be escaped. 

        RegexReplace( [Additional Notes], "([.!?])\\s*", "\\1\n" )

         

  • Mez's avatar
    Mez
    Qrew Captain

    Posting this again. 

    Found the solution: capturing is referred to with backslash 1, which needs to be escaped.

    RegexReplace( [Additional Notes], "([.!?])\\s*", "\\1\n" )