1 import "Prelude" hiding (group)
3 importJava "java.util.regex.Pattern" where
6 compile :: String -> Pattern
7 matcher :: Pattern -> String -> Matcher
9 importJava "java.util.regex.Matcher" where
14 Attempts to match the entire region against the pattern.
16 matches :: Matcher -> <Proc> Boolean
19 Returns the input subsequence matched by the previous match.
21 group :: Matcher -> <Proc> String
24 Returns the number of capturing groups in this matcher's pattern.
26 groupCount :: Matcher -> <Proc> Integer
29 Returns the input subsequence captured by the given group during the previous match operation.
32 groupNr :: Matcher -> Integer -> <Proc> Maybe String
35 Returns the input subsequence captured by the given named group during the previous match operation.
38 groupNm :: Matcher -> String -> <Proc> Maybe String
41 Attempts to find the next subsequence of the input sequence that matches the pattern.
44 matcherFind :: Matcher -> <Proc> Boolean
46 appendReplacement :: Matcher -> StringBuffer -> String -> <Proc> Matcher
47 appendTail :: Matcher -> StringBuffer -> <Proc> StringBuffer
50 replaceAll_ :: Matcher -> String -> String
52 @JavaName replaceFirst
53 replaceFirst_ :: Matcher -> String -> String
55 quoteReplacement :: String -> String
57 importJava "java.lang.StringBuffer" where
61 newStringBuffer :: () -> StringBuffer
64 freezeStringBuffer :: StringBuffer -> <Proc> String
69 Get parts matched by each group in the pattern, if a match is found.
71 matchGroups :: Pattern -> String -> Maybe [Maybe String]
72 matchGroups p s = runProc $ if matches m then Just $ mapN (\i -> groupNr m (i+1)) (groupCount m) else Nothing where
76 `replaceAll pattern replacement text` replaces all matches of `pattern` in the `text`
79 replaceAll :: String -> String -> String -> String
80 replaceAll pattern replacement text =
81 replaceAll_ (matcher (compile pattern) text) replacement
84 `replaceFirst pattern replacement text` replaces the first match of `pattern` in the `text`
87 replaceFirst :: String -> String -> String -> String
88 replaceFirst pattern replacement text =
89 replaceFirst_ (matcher (compile pattern) text) replacement
92 `substituteAll pattern f text` replaces all matches of `pattern` in the `text`
93 by the string returned by `f` given the matched region of the string as a parameter.
95 substituteAll :: String -> (String -> String) -> String -> String
96 substituteAll pattern f text = runProc do
97 m = matcher (compile pattern) text
98 buf = newStringBuffer ()
99 while (matcherFind m) do
100 appendReplacement m buf $ f $ group m
102 freezeStringBuffer buf
106 `substituteFirst pattern f text` replaces the first match of `pattern` in the `text`
107 by the string returned by `f` given the matched region of the string as a parameter.
109 substituteFirst :: String -> (String -> String) -> String -> String
110 substituteFirst pattern f text = runProc do
111 m = matcher (compile pattern) text
112 if (matcherFind m) then do
113 buf = newStringBuffer ()
114 appendReplacement m buf $ f $ group m
116 freezeStringBuffer buf
120 importJava "java.lang.String" where
123 `substring string beginIndex` Returns a string that is a substring of given string. The substring begins with the character at the specified index and extends to the end of the string.
126 substring :: String -> Integer -> String
129 `substringl string beginIndex endIndex` Returns a string that is a substring of given string. The substring begins at the specified `beginIndex` and extends to the character at index `endIndex - 1`. Thus the length of the substring is endIndex-beginIndex.
132 substringl :: String -> Integer -> Integer -> String