HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulepcre-heavy-1.0.0.3Haskell2010

Text.Regex.PCRE.Heavy

A usable regular expressions library on top of pcre-light.

  • 2 types
  • 1 class
  • 18 values
  • Packagepcre-heavy-1.0.0.3
  • Exports21
  • LanguageHaskell2010
  • LicenceLicenseRef-PublicDomain
  • SourceHeavy.hs

Matching

6 declarations
value(=~) :: ConvertibleStrings a SBS => a -> Regex -> Bool
#

Checks whether a string matches a regex.

Example1 expression
"https://val.packett.cool" =~ [re|^http.*|]True
value(≈) :: ConvertibleStrings a SBS => a -> Regex -> Bool
#

Checks whether a string matches a regex.

Example1 expression
"https://val.packett.cool" =~ [re|^http.*|]True

Same as =~.

valuescan
  1. :: (ConvertibleStrings SBS a, ConvertibleStrings a SBS)
  2. => Regex
  3. -> a
  4. -> [(a, [a])]
#

Searches the string for all matches of a given regex.

Example1 expression
scan [re|\s*entry (\d+) (\w+)\s*&?|] (" entry 1 hello  &entry 2 hi" :: String)[(" entry 1 hello  &",["1","hello"]),("entry 2 hi",["2","hi"])]

It is lazy! If you only need the first match, just apply head (or headMay from the "safe" library) -- no extra work will be performed!

Example1 expression
head $ scan [re|\s*entry (\d+) (\w+)\s*&?|] (" entry 1 hello  &entry 2 hi" :: String)(" entry 1 hello  &",["1","hello"])
valuescanRanges
  1. :: ConvertibleStrings a SBS
  2. => Regex
  3. -> a
  4. -> [((Int, Int), [(Int, Int)])]
#

Searches the string for all matches of a given regex, like scan, but returns positions inside of the string.

Example1 expression
scanRanges [re|\s*entry (\d+) (\w+)\s*&?|] (" entry 1 hello  &entry 2 hi" :: String)[((0,17),[(7,8),(9,14)]),((17,27),[(23,24),(25,27)])]

And just like scan, it's lazy.

Replacement

5 declarations
classclass RegexReplacement a where
#

Class of types that can serve as the replacement argument in the sub family of functions.

Instances4RegexReplacement

Replaces the first occurence of a given regex.

Example1 expression
sub [re|thing|] "world" "Hello, thing thing" :: String"Hello, world thing"
Example1 expression
sub [re|a|] "b" "c" :: String"c"
Example1 expression
sub [re|bad|] "xxxbad" "this is bad, right?" :: String"this is xxxbad, right?"

You can use functions! A function of ConvertibleStrings SBS gets the full match. A function of [ConvertibleStrings SBS] gets the groups. A function of ConvertibleStrings SBS → [ConvertibleStrings SBS] gets both.

Example1 expression
sub [re|%(\d+)(\w+)|] (\(d:w:_) -> "{" ++ d ++ " of " ++ w ++ "}" :: String) "Hello, %20thing" :: String"Hello, {20 of thing}"

Replaces all occurences of a given regex.

See sub for more documentation.

Example1 expression
gsub [re|thing|] "world" "Hello, thing thing" :: String"Hello, world world"
Example1 expression
gsub [re||] "" "Hello, world" :: String"Hello, world"

https://codeberg.org/valpackett/pcre-heavy/issues/2 >>> gsub [re|good|] "bad" "goodgoodgood" :: String "badbadbad"

Example1 expression
gsub [re|bad|] "xxxbad" "this is bad, right? bad" :: String"this is xxxbad, right? xxxbad"
Example1 expression
gsub [re|a|] "" "aaa" :: String""

Splitting

2 declarations
valuesplit
  1. :: (ConvertibleStrings SBS a, ConvertibleStrings a SBS)
  2. => Regex
  3. -> a
  4. -> [a]
#

Splits the string using the given regex.

Is lazy.

Example1 expression
split [re|%(begin|next|end)%|] ("%begin%hello%next%world%end%" :: String)["","hello","world",""]
Example1 expression
split [re|%(begin|next|end)%|] ("" :: String)[""]

QuasiQuoter

2 declarations
valuere :: QuasiQuoter
#

A QuasiQuoter for regular expressions that does a compile time check.

Building regexes

1 declaration
valueescape :: (ConvertibleStrings a SBS, ConvertibleStrings SBS a) => a -> a
#

Escapes the regex metacharacters in a string. In other words, given a string, produces a regex that matches just that string (or case variations of that string, if case-insenstive matching is enabled).

Example1 expression
("foo*bar"::String) =~ PCRE.compile (escape "foo*bar") []True

Types and stuff from pcre-light

3 declarations
datadata Regex
#

An abstract pointer to a compiled PCRE Regex structure The structure allocated by the PCRE library will be deallocated automatically by the Haskell storage manager.

Instances3Eq, Ord, Show
  • Eq RegexDefined in pcre-light-0.4.1.3 · Text.Regex.PCRE.Light.Base
  • Ord RegexDefined in pcre-light-0.4.1.3 · Text.Regex.PCRE.Light.Base
  • Show RegexDefined in pcre-light-0.4.1.3 · Text.Regex.PCRE.Light.Base
newtypenewtype PCREOption
#

A type for PCRE compile-time options. These are newtyped CInts, which can be bitwise-or'd together, using (Data.Bits..|.)

Instances5Eq, Ord, Read, Show, Lift
  • Eq PCREOptionDefined in pcre-light-0.4.1.3 · Text.Regex.PCRE.Light.Base
  • Ord PCREOptionDefined in pcre-light-0.4.1.3 · Text.Regex.PCRE.Light.Base
  • Read PCREOptionDefined in pcre-light-0.4.1.3 · Text.Regex.PCRE.Light.Base
  • Show PCREOptionDefined in pcre-light-0.4.1.3 · Text.Regex.PCRE.Light.Base
  • Lift PCREOptionDefined in pcre-heavy-1.0.0.3 · Text.Regex.PCRE.Heavy · orphan

Advanced raw stuff

2 declarations
valuerawMatch :: Regex -> SBS -> Int -> [PCREExecOption] -> Maybe [(Int, Int)]
#

Does raw PCRE matching (you probably shouldn't use this directly).

Example3 expressions
rawMatch [re|\w{2}|] "a a ab abc ba" 0 []Just [(4,6)]rawMatch [re|\w{2}|] "a a ab abc ba" 6 []Just [(7,9)]rawMatch [re|(\w)(\w)|] "a a ab abc ba" 0 []Just [(4,6),(4,5),(5,6)]

Orphan instances

1 instance