I found this thread and one of users on it posted the following line of code:
String[] digits2 = number.split("(?<=.)");
I have consulted a couple of sources- like 1 and 2-to decipher what this code mean but I can't figure it out. Can anybody explain what the argument in the split() method means?
Edit: To anyone who has the same question as I had, here's another helpful link
A metacharacter is a character that has a special meaning during pattern processing. You use metacharacters in regular expressions to define the search criteria and any text manipulations. Search string metacharacters are different from replacement string metacharacters.
The backslash \ is an escape character in Java Strings. That means backslash has a predefined meaning in Java. You have to use double backslash \\ to define a single backslash.
To escape a metacharacter you use the Java regular expression escape character - the backslash character. Escaping a character means preceding it with the backslash character. For instance, like this: \.
$ means "Match the end of the string" (the position after the last character in the string). Both are called anchors and ensure that the entire string is matched instead of just a substring.
This is a positive lookbehind. The overall expression means "after any character, but without capturing anything". Essentially, if the string looks like
ABC
then the matches would occur at |
, between the characters.
A|B|C|
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With