1

I have a peculiar regex kind of requirement.

I have a string like

Get Carter,Tigerland,Super, The,Wolf, The. 

Here "Super, The" and "Wolf, The" are single word.

I need to tokenize it as follow

"Get Carter" "Tigerland" "Super, The" "Wolf, The" 

The only thing I have to note is commas in single word are followed by space, while commas between two different words do not have a space following.

Is there anything in string tokenizer like checking for ",W", where W is any alphabet?

1 Answer 1

2

You want a negative lookahead, ",(?! )".

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, but i tried like this.. String Genre = "Get Carter,Tigerland,Super, The,Wolf, The"; StringTokenizer Genresplit = new StringTokenizer(Genre, ",(?! )"); while (Genresplit.hasMoreTokens()) { System.out.println(Genresplit.nextToken()); } I get like this Get Carter Tigerland Super The Wolf The -- All words separate...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.