Skip to content

Commit

Permalink
Add RegExUtils.dotAllMatcher(String, CharSequence) and deprecate
Browse files Browse the repository at this point in the history
RegExUtils.dotAllMatcher(String, String)
  • Loading branch information
garydgregory committed Jan 9, 2025
1 parent 1ea3bee commit 9bc57f7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="add" dev="ggregory" due-to="Gary Gregory">Add BasicThreadFactory.daemon().</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add ArrayUtils.startsWith.</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add Predicates.</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add RegExUtils.dotAllMatcher(String, CharSequence) and deprecate RegExUtils.dotAllMatcher(String, String).</action>
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump org.apache.commons:commons-parent from 73 to 78 #1267, #1277, #1283, #1288, #1302.</action>
<action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">[site] Bump org.codehaus.mojo:taglist-maven-plugin from 3.1.0 to 3.2.1 #1300.</action>
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/apache/commons/lang3/RegExUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ public static Pattern dotAll(final String regex) {
return Pattern.compile(regex, Pattern.DOTALL);
}

/**
* Compiles the given regular expression into a pattern with the {@link Pattern#DOTALL} flag, then creates a matcher that will match the given text against
* this pattern.
*
* @param regex The expression to be compiled.
* @param text The character sequence to be matched.
* @return A new matcher for this pattern.
* @since 3.18.0
*/
public static Matcher dotAllMatcher(final String regex, final CharSequence text) {
return dotAll(regex).matcher(text);
}

/**
* Compiles the given regular expression into a pattern with the {@link Pattern#DOTALL} flag, then creates a matcher that will match the given text against
* this pattern.
Expand All @@ -46,7 +59,9 @@ public static Pattern dotAll(final String regex) {
* @param text The character sequence to be matched.
* @return A new matcher for this pattern.
* @since 3.13.0
* @deprecated Use {@link #dotAllMatcher(String, CharSequence)}.
*/
@Deprecated
public static Matcher dotAllMatcher(final String regex, final String text) {
return dotAll(regex).matcher(text);
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/org/apache/commons/lang3/RegExUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public void testDotAll() {

@Test
public void testDotAllMatcher() {
assertTrue(RegExUtils.dotAllMatcher("<A>.*</A>", (CharSequence) "<A>\nxy\n</A>").matches());
}

@SuppressWarnings("deprecation")
@Test
public void testDotAllMatcherDeprecated() {
assertTrue(RegExUtils.dotAllMatcher("<A>.*</A>", "<A>\nxy\n</A>").matches());
}

Expand Down

0 comments on commit 9bc57f7

Please sign in to comment.