Forum Discussion

GabeFigueroa1's avatar
GabeFigueroa1
Qrew Member
9 months ago
Solved

insert newline into API downloaded text

A Pipeline API successfully retrieves text into the QuickBase Rich text field.  The sometimes-lengthy text does not have any CRLF so the text is all run together.

The User will be editing the text so it would be helpful to pre-insert the new line for them as the text can be long.

The new line needs to go before any single or multiple digits followed by a period & 1 space, ex. "1. " or "11. " or "215. ". There can be just a few to over 50 or more instances.

A Regex seems to identify the places in the text but have yet to be able to prepend the "\n" or "<br>" in subsequent pipeline steps.

'Find All Matches to a RegEx' has been used to find the areas.

In (1) pipeline the Rich Text field was being updated w/ the new line using the QuickBase Update step but each subsequent regex update wiped out the previous change.

{% set claimTxt = d.group_0 | replace(d.group_0, '<br>'+d.group_0) %}
{{ c.claim | replace(d.group_0, claimTxt)}}

Would think that the 'Apply Regular Expressions" should work but have not been able to find examples on how to set that up (below is one example).

Several other variations than the one shown above were used but did not get the new line to insert.

replace([\d][0-9]{1,4}[.],\n$&)

replaceAll([\d][0-9]{1,4}[.],\n$&)

substitute([\d][0-9]{0,4}[.],\n$&)



------------------------------
Gabe Figueroa
------------------------------
  • DougHenning1's avatar
    DougHenning1
    9 months ago

    There's a regex filter, so you can use that instead of the "Find All Matches to a RegEx" step.  This code should go in the field to store the text with the line breaks added:

    {% set ns = namespace(data=c.claim) -%}
    {% set myList = ns.data | regex('[^0-9]\d{1,4}\.\s', true) -%}
    {% for x in myList -%}
      {% set ns.data = ns.data.replace(x|string,  (x|string)[0] ~ '<br>' ~ (x|string)[1:]) -%}
    {% endfor -%}
    {{ ns.data }} 

    Line 1: need a namespace to modify a variable inside a loop

    Line 2: use regex to get a list of the numbers to break on, including the preceding character which is needed in the replace.

    Line 4: Add a line break before the number, and add the preceding character back before the line break.

    Hope that helps!



    ------------------------------
    Doug Henning
    ------------------------------

2 Replies

  • DougHenning1's avatar
    DougHenning1
    Community Manager

    Do the numbers have a space preceding them as well?  Otherwise the replace call will not be able to differentiate between numbers like "1. " and "11. " (replace doesn't use regular expressions).



    ------------------------------
    Doug Henning
    ------------------------------
    • DougHenning1's avatar
      DougHenning1
      Community Manager

      There's a regex filter, so you can use that instead of the "Find All Matches to a RegEx" step.  This code should go in the field to store the text with the line breaks added:

      {% set ns = namespace(data=c.claim) -%}
      {% set myList = ns.data | regex('[^0-9]\d{1,4}\.\s', true) -%}
      {% for x in myList -%}
        {% set ns.data = ns.data.replace(x|string,  (x|string)[0] ~ '<br>' ~ (x|string)[1:]) -%}
      {% endfor -%}
      {{ ns.data }} 

      Line 1: need a namespace to modify a variable inside a loop

      Line 2: use regex to get a list of the numbers to break on, including the preceding character which is needed in the replace.

      Line 4: Add a line break before the number, and add the preceding character back before the line break.

      Hope that helps!



      ------------------------------
      Doug Henning
      ------------------------------