Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesnt look ahead and look behind Regex work in Kotlin?

Tags:

regex

kotlin

Example:

    // Java
    System.out.println("one;two;th/;ree".split("(?<!/);").length);  // 3

    // Kotlin
    println("one;two;th/;ree".split("(?<!/);").size) // 1

How to correct this?

like image 231
Letfar Avatar asked Jan 25 '16 21:01

Letfar


1 Answers

In your Kotlin example you're not splitting by a Regex but by a String.

Try the following:

println("one;two;th/;ree".split(Regex("(?<!/);")).size) // 3
like image 56
mfulton26 Avatar answered Sep 22 '22 20:09

mfulton26