hledger-lib-1.12: Core data types, parsers and functionality for the hledger accounting tools

Safe Haskell | None
Language | Haskell2010

Hledger.Utils.Regex

Contents

- type aliases
- standard regex operations

Description

Easy regular expression helpers, currently based on regex-tdfa. These should:

- be cross-platform, not requiring C libraries
- support unicode
- support extended regular expressions
- support replacement, with backreferences etc.
- support splitting
- have mnemonic names
- have simple monomorphic types
- work with simple strings

Regex strings are automatically compiled into regular expressions the first time they are seen, and these are cached. If you use a huge number of unique regular expressions this might lead to increased memory usage. Several functions have memoised variants (*Memo), which also trade space for time.

Current limitations:

- (?i) and similar are not supported

Synopsis

- type Regexp = String
- type Replacement = String
- regexMatches :: Regexp -> String -> Bool
- regexMatchesCI :: Regexp -> String -> Bool
- regexReplace :: Regexp -> Replacement -> String -> String
- regexReplaceCI :: Regexp -> Replacement -> String -> String
- regexReplaceMemo :: Regexp -> Replacement -> String -> String
- regexReplaceCIMemo :: Regexp -> Replacement -> String -> String
- regexReplaceBy :: Regexp -> (String -> String) -> String -> String
- regexReplaceByCI :: Regexp -> (String -> String) -> String -> String

# type aliases

type Regexp = String Source #

Regular expression. Extended regular expression-ish syntax ? But does not support eg (?i) syntax.

type Replacement = String Source #

A replacement pattern. May include numeric backreferences (N).

# standard regex operations

regexMatches :: Regexp -> String -> Bool Source #

regexMatchesCI :: Regexp -> String -> Bool Source #

regexReplace :: Regexp -> Replacement -> String -> String Source #

Replace all occurrences of the regexp with the replacement pattern. The replacement pattern supports numeric backreferences (N) but no other RE syntax.

regexReplaceCI :: Regexp -> Replacement -> String -> String Source #

regexReplaceMemo :: Regexp -> Replacement -> String -> String Source #

A memoising version of regexReplace. Caches the result for each search pattern, replacement pattern, target string tuple.

regexReplaceCIMemo :: Regexp -> Replacement -> String -> String Source #

regexReplaceBy :: Regexp -> (String -> String) -> String -> String Source #

Replace all occurrences of the regexp, transforming each match with the given function.

regexReplaceByCI :: Regexp -> (String -> String) -> String -> String Source #