1

Is it possible to match multiline strings with match() function? I tried to apply match(/(abc)\rdef/) to a cell containing 2 lines of text abc & def, but it does not work. Is there a way to get "abc" as result?

Mathieu Saby
  • 125
  • 5
  • From the link below, it should work with \n instead of \r !? Actually with a find() instead of a match()...
    https://stackoverflow.com/questions/50758805/text-with-n-matching-in-regex-and-openrefine/50759334#50759334
    – B. Go Jan 31 '19 at 00:37

2 Answers2

0

Simply use \n (newline) instead of \r (carriage return).

value.match(/(abc)\ndef/)

enter image description here

But you have to indicate where the newline is. match has no "multliline" parameter, so the dot (.) doesn't match line breaks.

Ettore Rizza
  • 2,800
  • 2
  • 11
  • 23
0

Of course ! Thanx Ettore

And I found a way to do what I wanted with value.match(/(.*?\n)*(def)\n?(.*?\n?)*/)

enter image description here

Mathieu Saby
  • 125
  • 5