I don't have experience with regex in java, but I think that we can solve this using regexp and it can be easier than my examples.
I have a text with double || symbols. Text can looks like:
1)aaa||bbb||ccc,
2)aaa||||ccc,
3)||bbb||ccc,
4)|| ||cccc etc.
I want to extract text after first || -bbb , andr after second || - ccc. I did:
Pattern p = Pattern.compile("||",Pattern,DOTALL);
String types[] = p.split(stringToParse);
but this is not working when string doesn't have 3 parts.
Second idea is:
Pattern p = Pattern.compile("||",Pattern,DOTALL);
Matcher m= p.matcher(strToParse);
while (m.find()) {
System.out.println(m.group() + " " + m.start() + " " + m.end());
}
then I know when || occures and is possible to do substring.
Does exist easier and simpler way to solve this problem?
")` on the `String` object containing the input work? This gives you an array with the tokens of text before, in between and after the tag. The downside is that you will end up with one massive token in the beginning and end, if your input is an HTML page. – Birb Oct 31 '13 at 12:01
to || because it is not a html text. – tostao Oct 31 '13 at 12:59