Java splitting string by custom regex match
Posted
by slikz
on Stack Overflow
See other posts from Stack Overflow
or by slikz
Published on 2010-04-01T05:32:31Z
Indexed on
2010/04/01
5:33 UTC
Read the original article
Hit count: 187
I am completely new to regular expressions so I'm looking for a bit of help here.
I am compiling under JDK 1.5
Take this line as an example that I read from standard input:
ab:Some string po:bubblegum
What I would like to do is split by the two characters and colon. That is, once the line is split and put into a string array, these should be the terms:
ab:Some string
po:bubblegum
I have this regex right now:
String[] split = input.split("[..:]");
This splits at the semicolon; what I would like is for it to match two characters and a semicolon, but split at the space before that starts. Is this even possible?
Here is the output from the string array:
ab
Some String po
bubblegum
I've read about Pattern.compile() as well. Is this something I should be considering?
© Stack Overflow or respective owner