Skip to content

Commit e17d2a8

Browse files
committed
Added Regex.usingRe2j()
1 parent 05ac4d4 commit e17d2a8

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<version>1.8</version>
1212
</dependency>
1313
```
14-
(If you already have that dependency in your classpath, but you want to keep using the Java regex engine, you can disable re2j via `System.setProperty("jsoup.useRe2j", "false")`.) [#2407](https://github.com/jhy/jsoup/pull/2407)
14+
(If you already have that dependency in your classpath, but you want to keep using the Java regex engine, you can disable re2j via `System.setProperty("jsoup.useRe2j", "false")`.) You can confirm that the re2j engine has been enabled correctly by calling `Regex.usingRe2j()`. [#2407](https://github.com/jhy/jsoup/pull/2407)
1515

1616
* Added an instance method `Parser#unescape(String, boolean)` that unescapes HTML entities using the parser's configuration (e.g. to support error tracking), complementing the existing static utility `Parser.unescapeEntities(String, boolean)`. [#2396](https://github.com/jhy/jsoup/pull/2396)
1717
* Build: added CI coverage for JDK 25 [#2403](https://github.com/jhy/jsoup/pull/2403)

src/main/java/org/jsoup/helper/Regex.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class Regex {
3333
@throws ValidationException if the regex is invalid
3434
*/
3535
public static Regex compile(String regex) {
36-
if (hasRe2j && wantsRe2j()) {
36+
if (usingRe2j()) {
3737
return Re2jRegex.compile(regex);
3838
}
3939

@@ -49,6 +49,14 @@ public static Regex fromPattern(Pattern pattern) {
4949
return new Regex(pattern);
5050
}
5151

52+
/**
53+
Checks if re2j is available (on classpath) and enabled (via system property).
54+
@return true if re2j is available and enabled
55+
*/
56+
public static boolean usingRe2j() {
57+
return hasRe2j && wantsRe2j();
58+
}
59+
5260
static boolean wantsRe2j() {
5361
return Boolean.parseBoolean(System.getProperty(SharedConstants.UseRe2j, "true"));
5462
}

src/test/java/org/jsoup/helper/RegexTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ void tearDown() {
2828
@ValueSource(booleans = {false, true})
2929
void testRegexDelegates(boolean useRe2j) {
3030
Regex.wantsRe2j(useRe2j);
31+
assertEquals(Regex.usingRe2j(), useRe2j);
3132
String pattern = "(\\d+)";
3233
String input = "12345";
3334

0 commit comments

Comments
 (0)