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 8291133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:01:15+00:00 2026-06-08T13:01:15+00:00

If I try this (import java.util.regex.Pattern) (Pattern/compile )!@#$%^&*()) or this (def p #)!@#$%^&*()) I

  • 0

If I try this

(import java.util.regex.Pattern)
(Pattern/compile ")!@#$%^&*()")

or this

(def p #")!@#$%^&*()")

I have Clojure complaining that there is an unmatched / unclosed ). Why are brackets evaluated within this simple string? How to escape them? Thanks

EDIT: While escaping works in the clojure-specific syntax (#""), it doesn’t work with the Pattern/compile syntax that I do need because I have to compile the regex patter dynamically from a string.

I’ve tried with re-pattern, but I can’t escape properly for some reason:

(re-pattern "\)!@#$%^&*\(\)")
    java.lang.Exception: Unsupported escape character: \)
    java.lang.Exception: Unable to resolve symbol: ! in this context (NO_SOURCE_FILE:0)
    java.lang.Exception: No dispatch macro for: $
    java.lang.Exception: Unable to resolve symbol: % in this context (NO_SOURCE_FILE:0)
    java.lang.IllegalArgumentException: Metadata can only be applied to IMetas

EDIT 2 This little function may help:

(defn escape-all [x]
    (str "\\" (reduce #(str  %1 "\\" %2) x)))
  • 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-08T13:01:16+00:00Added an answer on June 8, 2026 at 1:01 pm

    I got it working by double escaping everything. Oh the joys of double escaping.

    => (re-pattern "\\)\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)")
    => #"\)\!\@\#\$\%\^\&\*\(\)"
    
    => (re-find (re-pattern "\\)\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)")
                ")!@#$%^&*()")
    => ")!@#$%^&*()"
    

    I would recommend writing a helper function str-to-pattern (or whatever you want to call it), that takes a string, double escapes everything it needs to, and then calls re-pattern on it.

    Edit: making a string to pattern function
    There are plenty of ways to do this, below is just one example. I start by making an smap of regex escape chars to their string replacement. An “smap” isn’t an actual type, but functionally it’s a map we will use to swap “old values” with “new values”, where “old values” are members of the keys of the smap, and “new values” are corresponding members of the vals of smap. In our case, this smap looks like {\( "\\(", \) "\\)" ...}.

    (def regex-char-esc-smap
      (let [esc-chars "()*&^%$#!"]
        (zipmap esc-chars
                (map #(str "\\" %) esc-chars))))
    

    Next is the actual function. I use the above smap to replace items in the string passed to it, then convert that back into a string and make a regex pattern out of it. I think the ->> macro makes the code more readable, but that’s just a personal preference.

    (defn str-to-pattern
      [string]
      (->> string
           (replace regex-char-esc-smap)
           (reduce str)
           re-pattern))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I try to compile this: import java.awt.* ; class obj { public static
Hello i have a problem with this aplication. import java.util.ArrayList; import java.util.List; import android.app.Activity;
When I try to run this code: import java.io.*; import java.util.*; public class TwoColor
So basically I have this constructor for the class League : import java.util.*; public
I have this Code... ifsDAO.java package source; import java.sql.*; import java.sql.SQLException; import java.util.*; public
I have something like this: import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.OutputStream; import java.util.HashMap; import
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
I have the following test code. import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.FutureTask; class MyTask
import java.util.*; import java.io.*; import java.util.regex.*; class ZiggyTest2 extends Thread{ String sa; public ZiggyTest2(String
I have the following code: import java.util.*; public class SellTransaction extends Transaction { private

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.