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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:50:29+00:00 2026-05-23T16:50:29+00:00

For example: If I write hello@#$%^ it would return false just because it includes

  • 0

For example:
If I write hello@#$%^ it would return false just because it includes a special character I prohibited.
If I write hello it would be true.
If I write $, it will be false.
The list of characters I want to exclude is similar to: ` ~ ! @ # $ % ^ & * { } [ ] ” ‘ : ; , . < > ? / | \
I just need a regex to detect if any of those following characters are in a string if they are it would return false. Thanks and sorry for the informality.

Regards,
Sam

  • 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-05-23T16:50:29+00:00Added an answer on May 23, 2026 at 4:50 pm

    Depending on your intent, the simplest approach might be to enumerate the characters you do want to allow, a la:

    if(myString.matches("[a-zA-Z0-9_ ]*")) ...
    

    This would allow any alphanumeric string containing underscores and spaces. If you really do need to just match strings containing an explicitly enumerated list of forbidden characters, then you will have to enumerate them and escape the ones that are special regex characters:

    import java.util.regex.Pattern;
    
    ...
    
    String forbiddenCharacters = "`~!@#$%^&*{}[]"':;,.<>?/|\\";
    if(!myString.matches(".*[" + Pattern.quote(forbiddenCharacters) + "].*")) ...
    

    A couple of notes:

    1. You will need to escape your backslash to get it into the forbiddenCharacters string.
    2. The Pattern class’s static quote() method allows you to escape a string so that it will be parsed by the regular expression engine as if it were the literal version of that string. That is, it prevents special regex characters from being processed as such.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example, how would I write a program like senuti ? Are there any
For example, I want to write an activity that launches when you return from
Example dump from the list of a directory: hello:3.1 GB world:1.2 MB foo:956.2 KB
Let's take example of a command example-command. I open terminal I write example-command in
I am trying to read in a string from a C# Response.Write(string example) into
I'm pretty new to XQuery and I'm trying to write an example function that
I frequently write throwaway code (in a research environment ) - for example to
For example, how can I write an expression where the following is implicitly applied:
For example, I write a method: Private Sub Command1_Click() Dim dom As New DOMDocument
For example, if I were to write a calendar app on top of AIR,

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.