need help in understanding this line: String[] digits = number.split("(?<=.)"); | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 2

need help in understanding this line: String[] digits = number.split("(?<=.)");

I wanna know exactly the meaning of this ("(?<=.)"). I encountered that line upon browsing for an algorithm in splitting an integer into digits. Thanks!

1st Jul 2021, 7:35 AM
Matthew Tangpus
Matthew Tangpus - avatar
3 Respuestas
+ 3
1st Jul 2021, 8:26 AM
Abhay
Abhay - avatar
+ 2
regex (?<=X) is positive lookbehind, mean place where (X) is before target position if X is . char , it is place after (each) char
1st Jul 2021, 6:39 PM
zemiak
+ 2
You just need a split("") since java 8 In java 1.7 or less you had to do split("\\B") to make sure not consider the first empty character matched.
2nd Jul 2021, 5:09 PM
Brando Calderón
Brando Calderón - avatar