-2

Hello I have a string like that

"
load
yes

test
2

10/05/2020
1
"

I search to extract each line like this

regex1 = load
regex2 = yes
regex3 = test
regex4 = 2
regex4 = 10/05/2020
regex5 = 1

But I search also to avoid if there is no match, for example I can have a case where i havn't 10/05/2020 so I can un a prédictive match as (10/05/2020).

I don't know also how many lines there will be, it can be more or less.

But structure is the same

X1
X2
space
X3
X4
space 
...

I don't found a regex tout isolate each X in différent group ou différent equation

Nitneuq
  • 1,988
  • 7
  • 25
  • 43

1 Answers1

0

You don't need a sophisticated regex for this, strictly speaking. You only have to split this by newline, in this case, any amount of newline.

The regex you need to split it by is \n+

Now if you do-

List<String> strList = str.split(new RegExp(r"\n+"));

Where str is-

String str = """load
yes


test
2

10/05/2020
1
""";

(Note: The str format itself is important, any extra newlines or whitespace will give you unwanted results)

You'll get the result-

[load, yes, test, 2, 10/05/2020, 1]

Check out the demo here

Chase
  • 4,266
  • 2
  • 9
  • 28