Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RegEx to Tokenize String

Tags:

java

regex

I'm trying to create a regex to tokenize a string. An example string would be.

John Mary, "Name=blah;Name=blahAgain" "Hand=1,2"

I'm trying to get back:

  • John
  • Mary
  • Name=blah;Name=blahAgain
  • Hand=1,2
like image 293
binarymelon Avatar asked Mar 20 '26 17:03

binarymelon


2 Answers

This was easy:

([^ ])+
like image 137
Monis Iqbal Avatar answered Mar 22 '26 06:03

Monis Iqbal


For that specific example, I would do:

([^\s]*)\s+([^,\s]*)\s*,\s*"([^"]*)"\s+"([^"]*)"

update: modified to split Mary and John

like image 44
slebetman Avatar answered Mar 22 '26 05:03

slebetman