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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:27:49+00:00 2026-06-03T14:27:49+00:00

Here’s the problem: user is presented with a text field, unto which may he

  • 0

Here’s the problem: user is presented with a text field, unto which may he or she type the filter. A filter, to filter unfiltered data. User, experiencing an Oracle Forms brainwashing, excpets no special characters other than %, which I guess more or less stands for “.*” regex in Java.

If the User Person is well behaved, given person will type stuff like “CTHULH%”, in which case I may construct a pattern:

Pattern.compile(inputText.replaceAll("%", ".*"));

But if the User Person hails from Innsmouth, insurmountably will he type “.+\[a-#$%^&*(” destroying my scheme with a few simple keystrokes. This will not work:

Pattern.compile(Pattern.quote(inputText).replaceAll("%", ".*"));

as it will put \Q at the beginning and \E at the end of the String, rendereing my % -> .* switch moot.

The question is: do I have to look up every special character in the Pattern code and escape it myself by adding “\\” in front, or can this be done automagically? Or am I so deep into the problem, I’m omitting some obvious way of resolution?

  • 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-03T14:27:52+00:00Added an answer on June 3, 2026 at 2:27 pm

    What about Pattern.compile(Pattern.quote(inputText).replaceAll("%", "\\E.*\\Q"));?

    This should result in the following pattern:

    input:   ".+\[a-#$%^&*(" 
    quote:   \Q".+\[a-#$%^&*("\E 
    replace: \Q".+\[a-#$\E.*\Q^&*("\E
    

    In case the % character was the first or last character you would get a \Q\E (if you only have the input % the expression would end up being \Q\E.*\Q\E) but this should still be a valid expression.

    Update:

    I forgot the difference between replace(...) and replaceAll(...): the replacement parameter in the former is a literal while the replacement in the latter is an expression itself. Thus – as you already stated in your comment – you need to call Pattern.compile(Pattern.quote(inputText).replaceAll("%", "\\\\E.*\\\\Q")); (quote the backslashes in the string and in the expression).

    From the documentation on String#replaceAll(...):

    Note that backslashes in the replacement string may cause the results to be different than if it were being treated as a literal replacement string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here is the scenario 1: user starts to type some word, autocomplete engine shows
Here is a simple timepicker to jQuery UI's datepicker <script type=text/javascript> /* <![CDATA[ */
Here's my situation: I have a Data Template set up which contains a ToggleButton
Here's the question. I have a table where I save some data, which I
Here is my problem...I have a page that loads a list of clients and
Here is an example: I have a file 1.js, which has some functions. I
here is a debatable question which i want to achieve not sure how .
Here is the piece of code which I use to get the count from
Here is my problem : I have a post controller with the action create.
Here my problem: @Assert\Regex( * pattern=/^[A-Za-z0-9][A-Za-z0-9\]*$/, * groups={creation, creation_logged} * ) I'm using the

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.