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

Safe HaskellNone
LanguageHaskell2010

Hledger.Utils.Regex

Contents

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 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

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.

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

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

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

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