Skip to content

Commit d5c2703

Browse files
authored
Merge pull request #14 from mspiegel/regex-substring
Match subsequence instead of entire input sequence.
2 parents 98d3fba + 80a8183 commit d5c2703

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/main/java/com/networknt/schema/PatternValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
5858
if (p != null) {
5959
try {
6060
Matcher m = p.matcher(node.asText());
61-
if (!m.matches()) {
61+
if (!m.find()) {
6262
errors.add(buildValidationMessage(at, pattern));
6363
}
6464
} catch (PatternSyntaxException pse) {

src/test/resources/tests/pattern.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,16 @@
1919
"valid": true
2020
}
2121
]
22+
},
23+
{
24+
"description": "pattern is not anchored",
25+
"schema": {"pattern": "a+"},
26+
"tests": [
27+
{
28+
"description": "matches a substring",
29+
"data": "xxaayy",
30+
"valid": true
31+
}
32+
]
2233
}
2334
]

0 commit comments

Comments
 (0)