introduction h1>
- JDK 1.8 li> ul>
split function h1>
notice that the split function takes a regular expression as an argument. The split function is defined as:
/**
* Splits this string around matches of the given <a
* href="../util/regex/Pattern.html#sum">regular expression</a>.
*
* <p> This method works as if by invoking the two-argument {@link
* #split(String, int) split} method with the given expression and a limit
* argument of zero. Trailing empty strings are therefore not included in
* the resulting array.
*
* <p> The string {@code "boo:and:foo"}, for example, yields the following
* results with these expressions:
*
* <blockquote><table cellpadding=1 cellspacing=0 summary="Split examples showing regex and result">
* <tr>
* <th>Regex</th>
* <th>Result</th>
* </tr>
* <tr><td align=center>:</td>
* <td>{@code { "boo", "and", "foo" }}</td></tr>
* <tr><td align=center>o</td>
* <td>{@code { "b", "", ":and:f" }}</td></tr>
* </table></blockquote>
*
*
* @param regex
* the delimiting regular expression
*
* @return the array of strings computed by splitting this string
* around matches of the given regular expression
*
* @throws PatternSyntaxException
* if the regular expression's syntax is invalid
*
* @see java.util.regex.Pattern
*
* @since 1.4
* @spec JSR-51
*/
public String[] split(String regex) { ... }
special symbol processing
The
split function takes a regular expression as an argument, so special processing is required when the special symbol of the regular expression is used as a delimiter.
For example, .
is a wildcard in regular expressions, and matches any single character
except for line breaks (\n, \r).
can be handled in two ways for special symbols:
- escaped. For example,
\.
- put it in brackets. For example, the
[.] code> li> ul>
Example
h1>
String[] s1 = "a.b.c".split("\\.");
System.out.println(Arrays.asList(s1)); //[a, b, c]
String[] s2 = "a.b.c".split("[.]");
System.out.println(Arrays.asList(s2)); //[a, b, c]
Reference
h1>
https://www.runoob.com/regexp/regexp-metachar.html
split function h1>
notice that the split function takes a regular expression as an argument. The split function is defined as:
/**
* Splits this string around matches of the given <a
* href="../util/regex/Pattern.html#sum">regular expression</a>.
*
* <p> This method works as if by invoking the two-argument {@link
* #split(String, int) split} method with the given expression and a limit
* argument of zero. Trailing empty strings are therefore not included in
* the resulting array.
*
* <p> The string {@code "boo:and:foo"}, for example, yields the following
* results with these expressions:
*
* <blockquote><table cellpadding=1 cellspacing=0 summary="Split examples showing regex and result">
* <tr>
* <th>Regex</th>
* <th>Result</th>
* </tr>
* <tr><td align=center>:</td>
* <td>{@code { "boo", "and", "foo" }}</td></tr>
* <tr><td align=center>o</td>
* <td>{@code { "b", "", ":and:f" }}</td></tr>
* </table></blockquote>
*
*
* @param regex
* the delimiting regular expression
*
* @return the array of strings computed by splitting this string
* around matches of the given regular expression
*
* @throws PatternSyntaxException
* if the regular expression's syntax is invalid
*
* @see java.util.regex.Pattern
*
* @since 1.4
* @spec JSR-51
*/
public String[] split(String regex) { ... }
special symbol processing
The
split function takes a regular expression as an argument, so special processing is required when the special symbol of the regular expression is used as a delimiter.
For example, .
is a wildcard in regular expressions, and matches any single character
except for line breaks (\n, \r).
can be handled in two ways for special symbols:
- escaped. For example,
\.
- put it in brackets. For example, the
[.] code> li> ul>
Exampleh1>
String[] s1 = "a.b.c".split("\\."); System.out.println(Arrays.asList(s1)); //[a, b, c] String[] s2 = "a.b.c".split("[.]"); System.out.println(Arrays.asList(s2)); //[a, b, c]
Reference
h1>
https://www.runoob.com/regexp/regexp-metachar.html
Read More:
- Split keyword in ABAP when the separator is at the beginning and end of the string
- How to use Python split() function (split array)
- Illegal escape character in string literal
- String operation to delete the character at the specified position
- Curl returns empty reply from server. Due to the processing of special characters, curl cannot be accessed and the browser can access it.
- ‘Conversion failed when converting date and/or time from character string.DB-Lib error message 241,
- Python conversion hex to string, high and low data processing
- Java.lang.Character . isdigit() and isletter() methods
- When MATLAB uses audioread, an error is reported: Error using which Must be a string scalar or character vector.
- Regular expressions filter special characters
- Failed to convert value of type ‘java.lang.String‘ to required type ‘java.util.Date‘;
- java.lang.NoSuchMethodError: org.json.JSONObject.put(Java/lang/String; Java/util/Collection;) “209151;”
- [Solved] Flowable Start Error: ClassCastException: java.time.LocalDateTime cannot be cast to java.lang.String
- A repeated string is composed of two identical strings. For example, abcabc is a repeated string with length of 6, while abcba does not have a duplicate string. Given any string, please help Xiaoqiang find the longest repeated substring.
- Java prompt unmappable character for encoding solution
- On the intern () method of string class in Java
- Error querying database.Cause:java.sql.SQLSyntaxErrorException:ORA-00911:invalid character
- Syntax error: unexpected character after line continuation character
- [resolved] error: Java: illegal character: ‘\ ufef’ or error: Java: class, interface or enum required
- Solving syntax error: unexpected character after line continuation character