Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java Regex Pipe Delimited ?

801904Nov 27 2012 — edited Nov 28 2012
Hello

I am trying to split the string which is pipe delimited. I am new to Regex and new to Java.

My Java/Regex code line to split is:

listColumns = aLine.split("\\|"); // my code has 2 backslash-escapes chars plus 1 pipe char but this forum does not allow me to put pipes or escapes correctly and plain text help is of NO HELP 8^(

My input string has 3 leading and 4 trailing pipe characters

My Output from split: (3 leading emptry strings work but 4 trailing pipe delimiters dont work)

SplitStrings2:[]
SplitStrings2:[]
SplitStrings2:[]
SplitStrings2:[col1]
SplitStrings2:[col3]
SplitStrings2:[col4]

I do get 3 empty strings for all 3 leading pipes but no empty strings for the any traling 4 pipe characters.

What do I need to change the code such that all repeated pipes resulted in same number of empty strings returned by split method?


thanks
YuriB

Edited by: yurib on Nov 28, 2012 12:25 PM

Edited by: yurib on Nov 28, 2012 12:25 PM

Edited by: yurib on Nov 28, 2012 12:29 PM
This post has been answered by jschellSomeoneStoleMyAlias on Nov 27 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 26 2012
Added on Nov 27 2012
6 comments
1,911 views