Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7763537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:41:03+00:00 2026-06-01T14:41:03+00:00

Do any of the Haskell PCRE libraries provide a function to escape regex metacharacters

  • 0

Do any of the Haskell PCRE libraries provide a function to escape regex metacharacters in a string? I.e. a function to take a string like “[$100]” and turn it into “\[\$100\]”.

I’m looking for the equivalent of Python’s re.escape, which I can’t seem to find in regex-pcre.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:41:05+00:00Added an answer on June 1, 2026 at 2:41 pm

    I’m not aware of such a function in any of
    the PCRE libraries, but depending on what
    you are trying to accomplish you could use
    PCRE quoting:

    {-# LANGUAGE OverloadedStrings #-}
    
    import qualified Data.ByteString.Char8 as B
    import Text.Regex.PCRE
    
    
    quotePCRE bs = B.concat [ "\\Q" , bs , "\\E" ]
    
    -- Of course, this won't work if the
    -- string to be quoted contains `\E` ,
    -- but that would be much eaiser to fix
    -- than writing a function taking into
    -- account all the necessary escaping.
    
    literal = "^[$100]$"
    
    quoted = quotePCRE literal
    
    main :: IO ()
    main = do B.putStr "literal: " >> B.putStrLn literal
    
              -- literal: ^[$100]$
    
              B.putStr "quoted: "  >> B.putStrLn quoted
    
              -- quoted: \Q^[$100]$\E
    
              putStrLn "literal =~ literal :: Bool"
              print ( literal =~ literal :: Bool )
    
              -- literal =~ literal :: Bool
              -- False
    
              putStrLn "literal =~ quoted :: Bool"
              print ( literal =~ quoted :: Bool )
    
              -- literal =~ quoted :: Bool
              -- True
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any function in haskell libraries that sorts integers in O(n) time?? [By,
Any pointers on how to solve efficiently the following function in Haskell, for large
Are there any Haskell bindings for quadratic programming libraries ? If not, which one
Is there any way to get static checks on Haskell arrays? Let's take this
Is there any way of doing something like this in haskell ? data Fruits
I need an analog of Haskell's foldl function to fold any STL containers. Expected
This question is for the people who know both Haskell (or any other functional
Is there any way to view the reduction steps in haskell, i.e trace the
I am starting to test Haskell for linear algebra. Does anyone have any recommendations
Is there any known implementation of Haskell MVar in C? There is an example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.