google / google/re2j

Behaviour of Matcher#split doesn't match java.util.regex

Open
#197 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1.3k
Forks
165
PR merge metrics
No merged PRs in 30d

Description

In the following example, the behaviour of re2j doesn't match the behaviour of `java.util.regex`, is this expected?

```java
import static java.util.Arrays.stream;
import static java.util.stream.Collectors.joining;

public class T {
public static void main(String[] args) {
String pattern = "\n(?: *\n)+";
String input = "";
int limit = 0;
{
System.err.println("> java.util.regex");
var p = java.util.regex.Pattern.compile(pattern);
print(p.split(input, limit));
}
{
System.err.println("\n> re2j");
var p = com.google.re2j.Pattern.compile(pattern);
print(p.split(input, limit));
}
}

private static void print(String[] split) {
System.err.println(
stream(split).map(x -> String.format("'%s'", x)).collect(joining(", ", "[", "]")));
}
}
```

```
> java.util.regex
['']

> re2j
[]
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.