0

Trying to parse out names with given samples

++++++++++++++++++SELIZABETH+COLLAZO+++++++++++++++++++
+++++++++++++++++++PALOMA+CORREA+++++++++++++++++++++++
+++++++++++++++++++NOAH+BLAKEMORE++++++++++++++++++++++

I've tried

//++(.*?)+(.*?)//++

but that's way off.

Would like to parse out the first and last name to two strings.

YCF_L
  • 51,266
  • 13
  • 85
  • 129

1 Answers1

5

You can use this regex (\w+)\+(\w+) or \+{2,}(.*?)\+(.*?)\+{2,} with Pattern like this :

String str = "++++++++++++++++++SELIZABETH+COLLAZO+++++++++++++++++++\n"
        + "+++++++++++++++++++PALOMA+CORREA+++++++++++++++++++++++\n"
        + "+++++++++++++++++++NOAH+BLAKEMORE++++++++++++++++++++++";

Pattern pattern = Pattern.compile("(\\w+)\\+(\\w+)");// or instead "\\+{2,}(.*?)\\+"(.*?)\\+{2,}
Matcher matcher = pattern.matcher(str);

while (matcher.find()) {
    System.out.println(matcher.group(1) + " " + matcher.group(2));
}

Outputs

SELIZABETH COLLAZO
PALOMA CORREA
NOAH BLAKEMORE
YCF_L
  • 51,266
  • 13
  • 85
  • 129
  • Hi down-voter, please put a comment when you down-vote a post, it is not legal to down-vote just like this, you have to respect the efforts of others, because we respect your efforts also. Thank you. – YCF_L Feb 19 '20 at 11:25