| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Yi.Regex
Synopsis
- data SearchOption
- makeSearchOptsM :: [SearchOption] -> String -> Either String SearchExp
- data SearchExp = SearchExp {
- seInput :: String
- seCompiled :: Regex
- seBackCompiled :: Regex
- seOptions :: [SearchOption]
- searchString :: SearchExp -> String
- searchRegex :: Direction -> SearchExp -> Regex
- emptySearch :: SearchExp
- emptyRegex :: Regex
- regexEscapeString :: String -> String
- reversePattern :: (Pattern, (t, DoPa)) -> (Pattern, (t, DoPa))
- data CompOption = CompOption {
- caseSensitive :: Bool
- multiline :: Bool
- rightAssoc :: Bool
- newSyntax :: Bool
- lastStarGreedy :: Bool
- newtype AllTextSubmatches (f :: Type -> Type) b = AllTextSubmatches {
- getAllTextSubmatches :: f b
- class Extract source => RegexLike regex source where
- matchAll :: regex -> source -> [MatchArray]
- matchOnceText :: regex -> source -> Maybe (source, MatchText source, source)
- makeRegex :: RegexMaker regex compOpt execOpt source => source -> regex
- makeRegexOptsM :: (RegexMaker regex compOpt execOpt source, MonadFail m) => compOpt -> execOpt -> source -> m regex
- defaultCompOpt :: RegexOptions regex compOpt execOpt => compOpt
- defaultExecOpt :: RegexOptions regex compOpt execOpt => execOpt
- data Regex
- (=~) :: (RegexMaker Regex CompOption ExecOption source, RegexContext Regex source1 target) => source1 -> source -> target
Documentation
data SearchOption Source #
Constructors
| IgnoreCase | Compile for matching that ignores char case |
| NoNewLine | Compile for newline-insensitive matching |
| QuoteRegex | Treat the input not as a regex but as a literal string to search for. |
Instances
makeSearchOptsM :: [SearchOption] -> String -> Either String SearchExp Source #
Constructors
| SearchExp | |
Fields
| |
searchString :: SearchExp -> String Source #
emptyRegex :: Regex Source #
The regular expression that matches nothing.
regexEscapeString :: String -> String Source #
Return an escaped (for parseRegex use) version of the string.
reversePattern :: (Pattern, (t, DoPa)) -> (Pattern, (t, DoPa)) Source #
Reverse a pattern. Note that the submatches will be reversed as well.
data CompOption Source #
Control whether the pattern is multiline or case-sensitive like Text.Regex and whether to capture the subgroups (\1, \2, etc). Controls enabling extra anchor syntax.
Constructors
| CompOption | |
Fields
| |
Instances
| Read CompOption | |
Defined in Text.Regex.TDFA.Common | |
| Show CompOption | |
Defined in Text.Regex.TDFA.Common | |
| RegexOptions Regex CompOption ExecOption | |
Defined in Text.Regex.TDFA.Common Methods blankCompOpt :: CompOption Source # blankExecOpt :: ExecOption Source # defaultCompOpt :: CompOption Source # defaultExecOpt :: ExecOption Source # setExecOpts :: ExecOption -> Regex -> Regex Source # getExecOpts :: Regex -> ExecOption Source # | |
| RegexMaker Regex CompOption ExecOption ByteString | |
Defined in Text.Regex.TDFA.ByteString Methods makeRegex :: ByteString -> Regex Source # makeRegexOpts :: CompOption -> ExecOption -> ByteString -> Regex Source # makeRegexM :: MonadFail m => ByteString -> m Regex Source # makeRegexOptsM :: MonadFail m => CompOption -> ExecOption -> ByteString -> m Regex Source # | |
| RegexMaker Regex CompOption ExecOption ByteString | |
Defined in Text.Regex.TDFA.ByteString.Lazy Methods makeRegex :: ByteString -> Regex Source # makeRegexOpts :: CompOption -> ExecOption -> ByteString -> Regex Source # makeRegexM :: MonadFail m => ByteString -> m Regex Source # makeRegexOptsM :: MonadFail m => CompOption -> ExecOption -> ByteString -> m Regex Source # | |
| RegexMaker Regex CompOption ExecOption Text | Since: regex-tdfa-1.3.1 |
Defined in Text.Regex.TDFA.Text Methods makeRegex :: Text -> Regex Source # makeRegexOpts :: CompOption -> ExecOption -> Text -> Regex Source # makeRegexM :: MonadFail m => Text -> m Regex Source # makeRegexOptsM :: MonadFail m => CompOption -> ExecOption -> Text -> m Regex Source # | |
| RegexMaker Regex CompOption ExecOption Text | Since: regex-tdfa-1.3.1 |
Defined in Text.Regex.TDFA.Text.Lazy Methods makeRegex :: Text -> Regex Source # makeRegexOpts :: CompOption -> ExecOption -> Text -> Regex Source # makeRegexM :: MonadFail m => Text -> m Regex Source # makeRegexOptsM :: MonadFail m => CompOption -> ExecOption -> Text -> m Regex Source # | |
| RegexMaker Regex CompOption ExecOption String | |
Defined in Text.Regex.TDFA.String Methods makeRegex :: String -> Regex Source # makeRegexOpts :: CompOption -> ExecOption -> String -> Regex Source # makeRegexM :: MonadFail m => String -> m Regex Source # makeRegexOptsM :: MonadFail m => CompOption -> ExecOption -> String -> m Regex Source # | |
| RegexMaker Regex CompOption ExecOption (Seq Char) | |
Defined in Text.Regex.TDFA.Sequence Methods makeRegex :: Seq Char -> Regex Source # makeRegexOpts :: CompOption -> ExecOption -> Seq Char -> Regex Source # makeRegexM :: MonadFail m => Seq Char -> m Regex Source # makeRegexOptsM :: MonadFail m => CompOption -> ExecOption -> Seq Char -> m Regex Source # | |
newtype AllTextSubmatches (f :: Type -> Type) b Source #
Used in results of RegexContext instances.
Constructors
| AllTextSubmatches | |
Fields
| |
Instances
| RegexLike a b => RegexContext a b (AllTextSubmatches (Array Int) (b, (MatchOffset, MatchLength))) | |
Defined in Text.Regex.Base.Context Methods match :: a -> b -> AllTextSubmatches (Array Int) (b, (MatchOffset, MatchLength)) Source # matchM :: MonadFail m => a -> b -> m (AllTextSubmatches (Array Int) (b, (MatchOffset, MatchLength))) Source # | |
| RegexLike a b => RegexContext a b (AllTextSubmatches (Array Int) b) | |
Defined in Text.Regex.Base.Context | |
| RegexLike a b => RegexContext a b (AllTextSubmatches [] (b, (MatchOffset, MatchLength))) | |
Defined in Text.Regex.Base.Context Methods match :: a -> b -> AllTextSubmatches [] (b, (MatchOffset, MatchLength)) Source # matchM :: MonadFail m => a -> b -> m (AllTextSubmatches [] (b, (MatchOffset, MatchLength))) Source # | |
| RegexLike a b => RegexContext a b (AllTextSubmatches [] b) | |
Defined in Text.Regex.Base.Context | |
class Extract source => RegexLike regex source where Source #
RegexLike is parametrized on a regular expression type and a source type to run the matching on.
There are default implementations: matchTest and matchOnceText use
matchOnce; matchCount and matchAllText use matchAll.
Conversely, matchOnce uses
matchOnceText and matchAll uses matchAllText. So a minimal complete
instance need to provide at least (matchOnce or matchOnceText) and
(matchAll or matchAllText). Additional definitions are often
provided where they will increase efficiency.
[ c | let notVowel = makeRegex "[^aeiou]" :: Regex, c <- ['a'..'z'], matchTest notVowel [c] ] "bcdfghjklmnpqrstvwxyz"
The strictness of these functions is instance dependent.
Minimal complete definition
Nothing
Methods
matchAll :: regex -> source -> [MatchArray] Source #
matchAll returns a list of matches. The matches are in order
and do not overlap. If any match succeeds but has 0 length then
this will be the last match in the list.
matchOnceText :: regex -> source -> Maybe (source, MatchText source, source) Source #
This can return a tuple of three items: the source before the match, an array of the match and captured substrings (with their indices), and the source after the match.
Instances
| RegexLike Regex ByteString | |
Defined in Text.Regex.TDFA.ByteString Methods matchOnce :: Regex -> ByteString -> Maybe MatchArray Source # matchAll :: Regex -> ByteString -> [MatchArray] Source # matchCount :: Regex -> ByteString -> Int Source # matchTest :: Regex -> ByteString -> Bool Source # matchAllText :: Regex -> ByteString -> [MatchText ByteString] Source # matchOnceText :: Regex -> ByteString -> Maybe (ByteString, MatchText ByteString, ByteString) Source # | |
| RegexLike Regex ByteString | |
Defined in Text.Regex.TDFA.ByteString.Lazy Methods matchOnce :: Regex -> ByteString -> Maybe MatchArray Source # matchAll :: Regex -> ByteString -> [MatchArray] Source # matchCount :: Regex -> ByteString -> Int Source # matchTest :: Regex -> ByteString -> Bool Source # matchAllText :: Regex -> ByteString -> [MatchText ByteString] Source # matchOnceText :: Regex -> ByteString -> Maybe (ByteString, MatchText ByteString, ByteString) Source # | |
| RegexLike Regex Text | Since: regex-tdfa-1.3.1 |
Defined in Text.Regex.TDFA.Text Methods matchOnce :: Regex -> Text -> Maybe MatchArray Source # matchAll :: Regex -> Text -> [MatchArray] Source # matchCount :: Regex -> Text -> Int Source # matchTest :: Regex -> Text -> Bool Source # matchAllText :: Regex -> Text -> [MatchText Text] Source # matchOnceText :: Regex -> Text -> Maybe (Text, MatchText Text, Text) Source # | |
| RegexLike Regex Text | Since: regex-tdfa-1.3.1 |
Defined in Text.Regex.TDFA.Text.Lazy Methods matchOnce :: Regex -> Text -> Maybe MatchArray Source # matchAll :: Regex -> Text -> [MatchArray] Source # matchCount :: Regex -> Text -> Int Source # matchTest :: Regex -> Text -> Bool Source # matchAllText :: Regex -> Text -> [MatchText Text] Source # matchOnceText :: Regex -> Text -> Maybe (Text, MatchText Text, Text) Source # | |
| RegexLike Regex String | |
Defined in Text.Regex.TDFA.String Methods matchOnce :: Regex -> String -> Maybe MatchArray Source # matchAll :: Regex -> String -> [MatchArray] Source # matchCount :: Regex -> String -> Int Source # matchTest :: Regex -> String -> Bool Source # matchAllText :: Regex -> String -> [MatchText String] Source # matchOnceText :: Regex -> String -> Maybe (String, MatchText String, String) Source # | |
| RegexLike Regex (Seq Char) | |
Defined in Text.Regex.TDFA.Sequence Methods matchOnce :: Regex -> Seq Char -> Maybe MatchArray Source # matchAll :: Regex -> Seq Char -> [MatchArray] Source # matchCount :: Regex -> Seq Char -> Int Source # matchTest :: Regex -> Seq Char -> Bool Source # matchAllText :: Regex -> Seq Char -> [MatchText (Seq Char)] Source # matchOnceText :: Regex -> Seq Char -> Maybe (Seq Char, MatchText (Seq Char), Seq Char) Source # | |
makeRegex :: RegexMaker regex compOpt execOpt source => source -> regex Source #
Use the defaultCompOpt and defaultExecOpt.
makeRegexOptsM :: (RegexMaker regex compOpt execOpt source, MonadFail m) => compOpt -> execOpt -> source -> m regex Source #
Specify your own options, reporting errors with fail
defaultCompOpt :: RegexOptions regex compOpt execOpt => compOpt Source #
Reasonable options (extended, caseSensitive, multiline regex).
defaultExecOpt :: RegexOptions regex compOpt execOpt => execOpt Source #
Reasonable options (extended, caseSensitive, multiline regex).
The TDFA backend specific Regex type, used by this module's RegexOptions and RegexMaker.
Instances
| RegexLike Regex ByteString | |
Defined in Text.Regex.TDFA.ByteString Methods matchOnce :: Regex -> ByteString -> Maybe MatchArray Source # matchAll :: Regex -> ByteString -> [MatchArray] Source # matchCount :: Regex -> ByteString -> Int Source # matchTest :: Regex -> ByteString -> Bool Source # matchAllText :: Regex -> ByteString -> [MatchText ByteString] Source # matchOnceText :: Regex -> ByteString -> Maybe (ByteString, MatchText ByteString, ByteString) Source # | |
| RegexLike Regex ByteString | |
Defined in Text.Regex.TDFA.ByteString.Lazy Methods matchOnce :: Regex -> ByteString -> Maybe MatchArray Source # matchAll :: Regex -> ByteString -> [MatchArray] Source # matchCount :: Regex -> ByteString -> Int Source # matchTest :: Regex -> ByteString -> Bool Source # matchAllText :: Regex -> ByteString -> [MatchText ByteString] Source # matchOnceText :: Regex -> ByteString -> Maybe (ByteString, MatchText ByteString, ByteString) Source # | |
| RegexLike Regex Text | Since: regex-tdfa-1.3.1 |
Defined in Text.Regex.TDFA.Text Methods matchOnce :: Regex -> Text -> Maybe MatchArray Source # matchAll :: Regex -> Text -> [MatchArray] Source # matchCount :: Regex -> Text -> Int Source # matchTest :: Regex -> Text -> Bool Source # matchAllText :: Regex -> Text -> [MatchText Text] Source # matchOnceText :: Regex -> Text -> Maybe (Text, MatchText Text, Text) Source # | |
| RegexLike Regex Text | Since: regex-tdfa-1.3.1 |
Defined in Text.Regex.TDFA.Text.Lazy Methods matchOnce :: Regex -> Text -> Maybe MatchArray Source # matchAll :: Regex -> Text -> [MatchArray] Source # matchCount :: Regex -> Text -> Int Source # matchTest :: Regex -> Text -> Bool Source # matchAllText :: Regex -> Text -> [MatchText Text] Source # matchOnceText :: Regex -> Text -> Maybe (Text, MatchText Text, Text) Source # | |
| RegexLike Regex String | |
Defined in Text.Regex.TDFA.String Methods matchOnce :: Regex -> String -> Maybe MatchArray Source # matchAll :: Regex -> String -> [MatchArray] Source # matchCount :: Regex -> String -> Int Source # matchTest :: Regex -> String -> Bool Source # matchAllText :: Regex -> String -> [MatchText String] Source # matchOnceText :: Regex -> String -> Maybe (String, MatchText String, String) Source # | |
| RegexContext Regex ByteString ByteString | |
Defined in Text.Regex.TDFA.ByteString Methods match :: Regex -> ByteString -> ByteString Source # matchM :: MonadFail m => Regex -> ByteString -> m ByteString Source # | |
| RegexContext Regex ByteString ByteString | |
Defined in Text.Regex.TDFA.ByteString.Lazy Methods match :: Regex -> ByteString -> ByteString Source # matchM :: MonadFail m => Regex -> ByteString -> m ByteString Source # | |
| RegexContext Regex Text Text | Since: regex-tdfa-1.3.1 |
| RegexContext Regex Text Text | Since: regex-tdfa-1.3.1 |
| RegexContext Regex String String | |
| RegexOptions Regex CompOption ExecOption | |
Defined in Text.Regex.TDFA.Common Methods blankCompOpt :: CompOption Source # blankExecOpt :: ExecOption Source # defaultCompOpt :: CompOption Source # defaultExecOpt :: ExecOption Source # setExecOpts :: ExecOption -> Regex -> Regex Source # getExecOpts :: Regex -> ExecOption Source # | |
| RegexMaker Regex CompOption ExecOption ByteString | |
Defined in Text.Regex.TDFA.ByteString Methods makeRegex :: ByteString -> Regex Source # makeRegexOpts :: CompOption -> ExecOption -> ByteString -> Regex Source # makeRegexM :: MonadFail m => ByteString -> m Regex Source # makeRegexOptsM :: MonadFail m => CompOption -> ExecOption -> ByteString -> m Regex Source # | |
| RegexMaker Regex CompOption ExecOption ByteString | |
Defined in Text.Regex.TDFA.ByteString.Lazy Methods makeRegex :: ByteString -> Regex Source # makeRegexOpts :: CompOption -> ExecOption -> ByteString -> Regex Source # makeRegexM :: MonadFail m => ByteString -> m Regex Source # makeRegexOptsM :: MonadFail m => CompOption -> ExecOption -> ByteString -> m Regex Source # | |
| RegexMaker Regex CompOption ExecOption Text | Since: regex-tdfa-1.3.1 |
Defined in Text.Regex.TDFA.Text Methods makeRegex :: Text -> Regex Source # makeRegexOpts :: CompOption -> ExecOption -> Text -> Regex Source # makeRegexM :: MonadFail m => Text -> m Regex Source # makeRegexOptsM :: MonadFail m => CompOption -> ExecOption -> Text -> m Regex Source # | |
| RegexMaker Regex CompOption ExecOption Text | Since: regex-tdfa-1.3.1 |
Defined in Text.Regex.TDFA.Text.Lazy Methods makeRegex :: Text -> Regex Source # makeRegexOpts :: CompOption -> ExecOption -> Text -> Regex Source # makeRegexM :: MonadFail m => Text -> m Regex Source # makeRegexOptsM :: MonadFail m => CompOption -> ExecOption -> Text -> m Regex Source # | |
| RegexMaker Regex CompOption ExecOption String | |
Defined in Text.Regex.TDFA.String Methods makeRegex :: String -> Regex Source # makeRegexOpts :: CompOption -> ExecOption -> String -> Regex Source # makeRegexM :: MonadFail m => String -> m Regex Source # makeRegexOptsM :: MonadFail m => CompOption -> ExecOption -> String -> m Regex Source # | |
| RegexMaker Regex CompOption ExecOption (Seq Char) | |
Defined in Text.Regex.TDFA.Sequence Methods makeRegex :: Seq Char -> Regex Source # makeRegexOpts :: CompOption -> ExecOption -> Seq Char -> Regex Source # makeRegexM :: MonadFail m => Seq Char -> m Regex Source # makeRegexOptsM :: MonadFail m => CompOption -> ExecOption -> Seq Char -> m Regex Source # | |
| RegexLike Regex (Seq Char) | |
Defined in Text.Regex.TDFA.Sequence Methods matchOnce :: Regex -> Seq Char -> Maybe MatchArray Source # matchAll :: Regex -> Seq Char -> [MatchArray] Source # matchCount :: Regex -> Seq Char -> Int Source # matchTest :: Regex -> Seq Char -> Bool Source # matchAllText :: Regex -> Seq Char -> [MatchText (Seq Char)] Source # matchOnceText :: Regex -> Seq Char -> Maybe (Seq Char, MatchText (Seq Char), Seq Char) Source # | |
| RegexContext Regex (Seq Char) (Seq Char) | |
(=~) :: (RegexMaker Regex CompOption ExecOption source, RegexContext Regex source1 target) => source1 -> source -> target Source #
This is the pure functional matching operator. If the target
cannot be produced then some empty result will be returned. If
there is an error in processing, then error will be called.