Link to home
Start Free TrialLog in
Avatar of Tolgar
Tolgar

asked on

How to split a string by comma or any number of space in Java and remove some pattern?

Hi,
I have this code in JAVA:

java.lang.String[] something = args[1].split(",");	

Open in new window


It splits the string by using commas in the original string and assigns it into an array.

Now what I wanna do is:

I want to split by comma or any number of space in between and remove all "g's" as a prefix:

Let's say I have this:

111111, 222222      333333,g444444     g555555

I wanna split this string and I wanna get this in the array:

111111
222222
333333
444444
555555


How can I do it by changing this code slightly in one or two lines lines?

Thanks,
Avatar of for_yan
for_yan
Flag of United States of America image

split([,g\\s]+);
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tolgar
Tolgar

ASKER

@for_yan: That's great!!! Can you please briefly tell me how you read this command:

split([,g\\s]+);

Open in new window


What does each term represent?

Thanks,

this splits on any number of consecutive commas, spaces and g characters