You need
test.split("\\|");
split
uses regular expression and in regex |
is a metacharacter representing the OR
operator. You need to escape that character using \
(written in String as "\\"
since \
is also a metacharacter in String literals and require another \
to escape it).
You can also use
test.split(Pattern.quote("|"));
and let Pattern.quote
create the escaped version of the regex representing |
.
Related Contents:
- regex for splitting a string while ignoring the brackets [duplicate]
- Java: splitting a comma-separated string but ignoring commas in quotes
- Split string to equal length substrings in Java
- Split string with dot as delimiter
- How to extract a substring using regex
- Regex to match a C-style multiline comment
- Java string split with “.” (dot) [duplicate]
- Java how to replace 2 or more spaces with single space in string and delete leading and trailing spaces
- Splitting a string at every n-th character
- How to extract numbers from a string and get an array of ints?
- Splitting on comma outside quotes
- Why does String.split need pipe delimiter to be escaped?
- How to split a string between letters and digits (or between digits and letters)?
- Using Java to find substring of a bigger string using Regular Expression
- How can non-ASCII characters be removed from a string?
- How do I convert CamelCase into human-readable names in Java?
- How to split String with some separator but without removing that separator in Java? [duplicate]
- Get the index of a pattern in a string using regex
- Java – Best way to grab ALL Strings between two Strings? (regex?)
- How to use regex in String.contains() method in Java
- Compare one String with multiple values in one expression
- Check and extract a number from a String in Java
- Extract string between two strings in java
- Use Java and RegEx to convert casing in a string
- Java split is eating my characters
- Extracting pairs of words using String.split()
- Replace the last part of a string
- Remove trailing zero in Java
- What is the simplest way to convert a Java string from all caps (words separated by underscores) to CamelCase (no word separators)?
- Why String.replaceAll() in java requires 4 slashes “\\\\” in regex to actually replace “\”?
- Java: Split string when an uppercase letter is found
- Java String.split() Regex
- Remove all empty lines
- Remove all non-“word characters” from a String in Java, leaving accented characters?
- Split a string, at every nth position
- Java String.replace/replaceAll not working
- How to Split a mathematical expression on operators as delimiters, while keeping them in the result?
- Check if string ends with certain pattern
- Validate a file name on Windows
- Java replace all square brackets in a string
- Splitting a string with multiple spaces
- Java string to date conversion
- Converting ‘ArrayList to ‘String[]’ in Java
- Regex for splitting a string using space when not surrounded by single or double quotes
- Java Regex Capturing Groups
- RegEx to split camelCase or TitleCase (advanced)
- Extract time from date String
- Java – removing first character of a string
- Detect and extract url from a string?
- How do I check if a char is a vowel?