2

I would like to tokenize the following string. "I went home with Mark's brother, to play a video game." result should be like this.

I
went
home
with
Mark
'
s
brother
to
,
play
a
video
game
.

Can you please tell me how to do it using regex.

2
  • do you have some code you tried so far? Commented Jul 18, 2012 at 9:52
  • yes the dot is in. and sorry the comma is also in. I just corrected it. Commented Jul 18, 2012 at 9:53

1 Answer 1

2

If you really want the ,, . and ' as separate tokens, you could split like this:

String str = "I went home with Mark's brother, to play a video game.";
String[] tokens = str.split("(\\s|(?=[,.'])|(?<=[,.']))");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.