1 package lv.id.jc.piglatin.core;
2
3 import java.util.function.Function;
4 import java.util.regex.Matcher;
5 import java.util.regex.Pattern;
6
7 import org.springframework.stereotype.Component;
8
9
10
11
12 @Component
13 public class WordsMatcher implements Function<String, Matcher> {
14 private static final Pattern WORD = Pattern.compile("""
15 # A word contains only Unicode letters and apostrophe (') in the middle
16 ( # Start of the group
17 \\p{L} # Any Unicode letter
18 | # OR
19 (?<=\\p{L}) # Positive lookbehind for a Unicode letter
20 ' # An apostrophe
21 (?=\\p{L}) # Positive lookahead for a Unicode letter
22 )+ # One or more of the previous group
23 """,
24 Pattern.COMMENTS + Pattern.CASE_INSENSITIVE);
25
26
27
28
29
30
31
32
33 @Override
34 public Matcher apply(String phrase) {
35 return WORD.matcher(phrase);
36 }
37 }