regex-1.1.0.2: Toolkit for regex-base

Safe Haskell | None
Language | Haskell2010

Text.RE.Tools.Find

Contents

- Find
- IsRegex
- Replace

Synopsis

- data FindMethods s = FindMethods {
  - doesDirectoryExistDM :: s -> IO Bool
  - listDirectoryDM :: s -> IO [s]
  - combineDM :: s -> s -> s
  }
- findMatches_ :: IsRegex re s => FindMethods s -> re -> s -> IO [s]
- findMatches_' :: IsRegex re s => FindMethods s -> ([s] -> [s]) -> (Match s -> Bool) -> re -> s -> IO [s]
- class Replace s => IsRegex re s where
  - matchOnce :: re -> s -> Match s
  - matchMany :: re -> s -> Matches s
  - makeRegex :: (Functor m, Monad m, MonadFail m) => s -> m re
  - makeRegexWith :: (Functor m, Monad m, MonadFail m) => SimpleREOptions -> s -> m re
  - makeSearchReplace :: (Functor m, Monad m, MonadFail m, IsRegex re s) => s -> s -> m (SearchReplace re s)
  - makeSearchReplaceWith :: (Functor m, Monad m, MonadFail m, IsRegex re s) => SimpleREOptions -> s -> s -> m (SearchReplace re s)
  - makeEscaped :: (Functor m, Monad m, MonadFail m) => (s -> s) -> s -> m re
  - makeEscapedWith :: (Functor m, Monad m, MonadFail m) => SimpleREOptions -> (s -> s) -> s -> m re
  - regexSource :: re -> s
- data SearchReplace re s = SearchReplace {
  - getSearch :: !re
  - getTemplate :: !s
  }
- searchReplaceAll :: IsRegex re s => SearchReplace re s -> s -> s
- searchReplaceFirst :: IsRegex re s => SearchReplace re s -> s -> s
- module Text.RE.Replace

# Find

The Find toolkit traverses directory trees invoking actions for each file that matches a RE.

See the Regex Tools tutorial at http://re-tutorial-tools.regex.uk

data FindMethods s Source #

as we don't want the `directory` and FilePath dependencies we will abstract the three calls we need into this record type

Constructors

FindMethods |

Fields

- doesDirectoryExistDM :: s -> IO Bool

  doesDirectoryExist from System.Directory

- listDirectoryDM :: s -> IO [s]

  either getDirectoryContents or listDirectory from System.Directory

- combineDM :: s -> s -> s

  / from System.FilePath

findMatches_ :: IsRegex re s => FindMethods s -> re -> s -> IO [s] Source #

recursively list all files whose filename matches given RE, sorting the list into ascending order; if the argument path has a trailing `/` then it will be removed

findMatches_' Source #

Arguments

:: IsRegex re s |
=> FindMethods s | the directory and filepath methods
-> ([s] -> [s]) | result post-processing function
-> (Match s -> Bool) | filtering function
-> re | re to be matched against the leaf filename
-> s | root directory of the search
-> IO [s] |

recursively list all files whose filename matches given RE, using the given function to determine which matches to accept

# IsRegex

class Replace s => IsRegex re s where Source #

the `IsRegex` class allows polymorhic tools to be written that will work with a variety of regex back ends and text types

Minimal complete definition

matchOnce, matchMany, makeRegexWith, makeSearchReplaceWith, regexSource

Methods

matchOnce :: re -> s -> Match s Source #

finding the first match

matchMany :: re -> s -> Matches s Source #

finding all matches

makeRegex :: (Functor m, Monad m, MonadFail m) => s -> m re Source #

compiling an RE, failing if the RE is not well formed

makeRegexWith :: (Functor m, Monad m, MonadFail m) => SimpleREOptions -> s -> m re Source #

comiling an RE, specifying the `SimpleREOptions`

makeSearchReplace :: (Functor m, Monad m, MonadFail m, IsRegex re s) => s -> s -> m (SearchReplace re s) Source #

compiling a `SearchReplace` template from the RE text and the template Text, failing if they are not well formed

makeSearchReplaceWith :: (Functor m, Monad m, MonadFail m, IsRegex re s) => SimpleREOptions -> s -> s -> m (SearchReplace re s) Source #

compiling a `SearchReplace` template specifying the `SimpleREOptions` for the RE

makeEscaped :: (Functor m, Monad m, MonadFail m) => (s -> s) -> s -> m re Source #

incorporate an escaped string into a compiled RE with the default options

makeEscapedWith :: (Functor m, Monad m, MonadFail m) => SimpleREOptions -> (s -> s) -> s -> m re Source #

incorporate an escaped string into a compiled RE with the specified `SimpleREOptions`

regexSource :: re -> s Source #

extract the text of the RE from the RE

#### Instances

Instances details

IsRegex RE ByteString Source # |

Instance details

Defined in Text.RE.TDFA.ByteString

Methods

matchOnce :: RE -> ByteString -> Match ByteString Source #

matchMany :: RE -> ByteString -> Matches ByteString Source #

makeRegex :: (Functor m, Monad m, MonadFail m) => ByteString -> m RE Source #

makeRegexWith :: (Functor m, Monad m, MonadFail m) => SimpleREOptions -> ByteString -> m RE Source #

makeSearchReplace :: (Functor m, Monad m, MonadFail m, IsRegex RE ByteString) => ByteString -> ByteString -> m (SearchReplace RE ByteString) Source #

makeSearchReplaceWith :: (Functor m, Monad m, MonadFail m, IsRegex RE ByteString) => SimpleREOptions -> ByteString -> ByteString -> m (SearchReplace RE ByteString) Source #

makeEscaped :: (Functor m, Monad m, MonadFail m) => (ByteString -> ByteString) -> ByteString -> m RE Source #

makeEscapedWith :: (Functor m, Monad m, MonadFail m) => SimpleREOptions -> (ByteString -> ByteString) -> ByteString -> m RE Source #

regexSource :: RE -> ByteString Source #

IsRegex RE ByteString Source # |

Instance details

Defined in Text.RE.TDFA.ByteString.Lazy

Methods

matchOnce :: RE -> ByteString -> Match ByteString Source #

matchMany :: RE -> ByteString -> Matches ByteString Source #

makeRegex :: (Functor m, Monad m, MonadFail m) => ByteString -> m RE Source #

makeRegexWith :: (Functor m, Monad m, MonadFail m) => SimpleREOptions -> ByteString -> m RE Source #

makeSearchReplace :: (Functor m, Monad m, MonadFail m, IsRegex RE ByteString) => ByteString -> ByteString -> m (SearchReplace RE ByteString) Source #

makeSearchReplaceWith :: (Functor m, Monad m, MonadFail m, IsRegex RE ByteString) => SimpleREOptions -> ByteString -> ByteString -> m (SearchReplace RE ByteString) Source #

makeEscaped :: (Functor m, Monad m, MonadFail m) => (ByteString -> ByteString) -> ByteString -> m RE Source #

makeEscapedWith :: (Functor m, Monad m, MonadFail m) => SimpleREOptions -> (ByteString -> ByteString) -> ByteString -> m RE Source #

regexSource :: RE -> ByteString Source #

IsRegex RE Text Source # |

Instance details

Defined in Text.RE.TDFA.Text

Methods

matchOnce :: RE -> Text -> Match Text Source #

matchMany :: RE -> Text -> Matches Text Source #

makeRegex :: (Functor m, Monad m, MonadFail m) => Text -> m RE Source #

makeRegexWith :: (Functor m, Monad m, MonadFail m) => SimpleREOptions -> Text -> m RE Source #

makeSearchReplace :: (Functor m, Monad m, MonadFail m, IsRegex RE Text) => Text -> Text -> m (SearchReplace RE Text) Source #

makeSearchReplaceWith :: (Functor m, Monad m, MonadFail m, IsRegex RE Text) => SimpleREOptions -> Text -> Text -> m (SearchReplace RE Text) Source #

makeEscaped :: (Functor m, Monad m, MonadFail m) => (Text -> Text) -> Text -> m RE Source #

makeEscapedWith :: (Functor m, Monad m, MonadFail m) => SimpleREOptions -> (Text -> Text) -> Text -> m RE Source #

regexSource :: RE -> Text Source #

IsRegex RE Text Source # |

Instance details

Defined in Text.RE.TDFA.Text.Lazy

Methods

matchOnce :: RE -> Text -> Match Text Source #

matchMany :: RE -> Text -> Matches Text Source #

makeRegex :: (Functor m, Monad m, MonadFail m) => Text -> m RE Source #

makeRegexWith :: (Functor m, Monad m, MonadFail m) => SimpleREOptions -> Text -> m RE Source #

makeSearchReplace :: (Functor m, Monad m, MonadFail m, IsRegex RE Text) => Text -> Text -> m (SearchReplace RE Text) Source #

makeSearchReplaceWith :: (Functor m, Monad m, MonadFail m, IsRegex RE Text) => SimpleREOptions -> Text -> Text -> m (SearchReplace RE Text) Source #

makeEscaped :: (Functor m, Monad m, MonadFail m) => (Text -> Text) -> Text -> m RE Source #

makeEscapedWith :: (Functor m, Monad m, MonadFail m) => SimpleREOptions -> (Text -> Text) -> Text -> m RE Source #

regexSource :: RE -> Text Source #

IsRegex RE String Source # |

Instance details

Defined in Text.RE.TDFA.String

Methods

matchOnce :: RE -> String -> Match String Source #

matchMany :: RE -> String -> Matches String Source #

makeRegex :: (Functor m, Monad m, MonadFail m) => String -> m RE Source #

makeRegexWith :: (Functor m, Monad m, MonadFail m) => SimpleREOptions -> String -> m RE Source #

makeSearchReplace :: (Functor m, Monad m, MonadFail m, IsRegex RE String) => String -> String -> m (SearchReplace RE String) Source #

makeSearchReplaceWith :: (Functor m, Monad m, MonadFail m, IsRegex RE String) => SimpleREOptions -> String -> String -> m (SearchReplace RE String) Source #

makeEscaped :: (Functor m, Monad m, MonadFail m) => (String -> String) -> String -> m RE Source #

makeEscapedWith :: (Functor m, Monad m, MonadFail m) => SimpleREOptions -> (String -> String) -> String -> m RE Source #

regexSource :: RE -> String Source #

IsRegex RE (Seq Char) Source # |

Instance details

Defined in Text.RE.TDFA.Sequence

Methods

matchOnce :: RE -> Seq Char -> Match (Seq Char) Source #

matchMany :: RE -> Seq Char -> Matches (Seq Char) Source #

makeRegex :: (Functor m, Monad m, MonadFail m) => Seq Char -> m RE Source #

makeRegexWith :: (Functor m, Monad m, MonadFail m) => SimpleREOptions -> Seq Char -> m RE Source #

makeSearchReplace :: (Functor m, Monad m, MonadFail m, IsRegex RE (Seq Char)) => Seq Char -> Seq Char -> m (SearchReplace RE (Seq Char)) Source #

makeSearchReplaceWith :: (Functor m, Monad m, MonadFail m, IsRegex RE (Seq Char)) => SimpleREOptions -> Seq Char -> Seq Char -> m (SearchReplace RE (Seq Char)) Source #

makeEscaped :: (Functor m, Monad m, MonadFail m) => (Seq Char -> Seq Char) -> Seq Char -> m RE Source #

makeEscapedWith :: (Functor m, Monad m, MonadFail m) => SimpleREOptions -> (Seq Char -> Seq Char) -> Seq Char -> m RE Source #

regexSource :: RE -> Seq Char Source #

data SearchReplace re s Source #

contains a compiled RE and replacement template

Constructors

SearchReplace |

Fields

- getSearch :: !re

  the RE to match a string to replace

- getTemplate :: !s

  the replacement template with ${cap} used to identify a capture (by number or name if one was given) and `$$` being used to escape a single `$`

#### Instances

Instances details

Functor (SearchReplace re) Source # |
Instance details Defined in Text.RE.ZeInternals.Types.SearchReplace Methods fmap :: (a -> b) -> SearchReplace re a -> SearchReplace re b Source # (<$) :: a -> SearchReplace re b -> SearchReplace re a Source #
(Show re, Show s) => Show (SearchReplace re s) Source # |
Instance details Defined in Text.RE.ZeInternals.Types.SearchReplace Methods showsPrec :: Int -> SearchReplace re s -> ShowS Source # show :: SearchReplace re s -> String Source # showList :: [SearchReplace re s] -> ShowS Source #

searchReplaceAll :: IsRegex re s => SearchReplace re s -> s -> s Source #

search and replace all matches in the argument text; e.g., this function will convert every YYYY-MM-DD format date in its argument text into a DD/MM/YYYY date:

    searchReplaceAll [ed|${y}([0-9]{4})-0*${m}([0-9]{2})-0*${d}([0-9]{2})///${d}/${m}/${y}|]

searchReplaceFirst :: IsRegex re s => SearchReplace re s -> s -> s Source #

search and replace the first occurrence only (if any) in the input text e.g., to prefix the first string of four hex digits in the imput text, if any, with `0x`:

    searchReplaceFirst [ed|[0-9A-Fa-f]{4}///0x$0|]

# Replace

module Text.RE.Replace