Java regex, delete content to the left of comma -
i got string bunch of numbers separated "," in following form :
1.2223232323232323,74.00
i want them string [], need number right of comma. (74.00). the list have abouth 10,000 different lines 1 above. right i'm using string.split(",") gives me :
system.out.println(string[1]) = 1.2223232323232323 74.00
why not split 2 diefferent indexds? thought should on split :
system.out.println(string[1]) = 1.2223232323232323 system.out.println(string[2]) = 74.00
but, on string[] array = string.split (",") produces 1 index both values separated newline.
and need 74.00 assume need use regex, kind of greek me. me out :)?
if it's in file:
scanner sc = new scanner(new file("...")); sc.usedelimiter("(\r?\n)?.*?,"); while (sc.hasnext()) system.out.println(sc.next());
if it's 1 giant string, separated new-lines:
string onegiantstring = "1.22,74.00\n1.22,74.00\n1.22,74.00"; scanner sc = new scanner(onegiantstring); sc.usedelimiter("(\r?\n)?.*?,"); while (sc.hasnext()) system.out.println(sc.next());
if it's single string each:
string line = "1.2223232323232323,74.00"; system.out.println(line.replacefirst(".*?,", ""));
regex explanation:
(\r?\n)?
means optional new-line character.
.
means wildcard.
.*?
means 0 or more wildcards (*?
opposed *
means non-greedy matching, doesn't mean you).
,
means, well, ..., comma.
split
file or single string:
string line = "1.2223232323232323,74.00"; string value = line.split(",")[1];
split
1 giant string (also needs regex) (but i'd prefer scanner
, doesn't need memory):
string line = "1.22,74.00\n1.22,74.00\n1.22,74.00"; string[] array = line.split("(\r?\n)?.*?,"); (int = 1; < array.length; i++) // first element empty system.out.println(array[i]);
Comments
Post a Comment