3

I have text field that contains data in this format

1001.01:abcdefgh.1001.02:abcdefghijkl.1001.03:abcdefghfsdqfs.

I would like to insert an automatic line break so the result would be this :

1001.01:abcdefgh.
1001.02:abcdefghijkl.
1001.03:abcdefghfsdqfs.

other example with a field contains this

1245.01:qsdfqsdf.1245.02:qdfqsdmkj.1245.03:dfsdmfjmdf

I need that

1245.01:qsdfqsdf
1245.02:qdfqsdmkj.
1245.03:dfsdmfjmdf

So basically I need a way to insert a /n at the beginning of each xxxx.xx (x always being a number)

3
  • Where exactly? To the field itself, to a new field or just in labeling? Commented Jul 1, 2022 at 14:57
  • And what exactly is your fixed sequence? Any string of a-z characters? Or .1001? Commented Jul 1, 2022 at 14:58
  • this should apply to all values contained in this field.
    – tonyduky
    Commented Jul 1, 2022 at 15:15

1 Answer 1

4

This regular expression will gave you the expected result :

regexp_replace(
    "your_field",
    '(\\d{4}[.]\\d{2})',
    '\n\\1'
)

It will insert a \n even for the first occurence, so first characters in your examples. If you want to avoid that the expression will be :

regexp_replace(
    "your_field",
    '(.)(\\d{4}[.]\\d{2})',  -- (point `.` here means any single character)
    '\\1\n\\2'
)
2
  • just edited my question!
    – tonyduky
    Commented Jul 1, 2022 at 15:08
  • two things : 1) god, I love code. 2) you're the man!
    – tonyduky
    Commented Jul 1, 2022 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.