1

I'm trying to find a way to insert line breaks into certain places in a text area column in a NetSuite saved search. In some instances this "comments" value contains data separated by line breaks with each line started by a digit followed by a period. The issue is that when this data is presented to be included as part of the results, the line breaks are removed, causing everything to run together. For the most part, I've been able to at least find where I need to insert the line breaks with the following:

REGEXP_REPLACE({notes}, '\d{1,2}\.', '<br />', 3, 0, 'i')

The problem, though, is that replaces all of the numerical "bullet points" except for what may be at the very first (typically '1.'), which is not desirable. Is there a way to re-insert these line breaks and keep the numerical bullets?

Michael McCauley
  • 853
  • 1
  • 12
  • 37

1 Answers1

1

You can re-use the matched text in the replacement pattern through backreferences:

REGEXP_REPLACE({notes}, '(\d{1,2}\.)', '<br />\1', 3, 0, NULL)

This will start searching for a match, case-sensitively (note I replaced 'i' with NULL since digits and a dot char are casefree chars), from the third position in the string, and will replace all matches (due to the 0 occurrence argument) with the same text as matched with <br /> prepended to it.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • Awesome, thank you. This does what I need. Grouping the matches with the parentheses is what I think really did the trick. I had previously tried the "\1" with no luck, and the grouping in the regex is what made the difference. – Michael McCauley Oct 04 '21 at 13:45
  • @MichaelMcCauley That \1 is a backreference, and it only works when you use a capturing group in the pattern, a pair of unescaped parentheses. – Wiktor Stribiżew Oct 04 '21 at 13:59