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

  • Home
  • SEARCH
  • 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 623583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:06:29+00:00 2026-05-13T19:06:29+00:00

I am pretty new to regular expressions. I want to write a regular expression

  • 0

I am pretty new to regular expressions. I want to write a regular expression which validates whether the given string has only certain characters. If the string has any other characters than these it should not be matched.

The characters I want are:

 & ' : , / - ( ) . # " ; A-Z a-z 0-9
  • 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-13T19:06:30+00:00Added an answer on May 13, 2026 at 7:06 pm

    Try this:

    $val =~ m/^[&':,\/\-().#";A-Za-z0-9]+$/;
    

    $val will match if it has at least one character and consists entirely of characters in that character set. An empty string will not be matched (if you want an empty string to match, change the last + to a *).

    You can test it out yourself:

    # Here's the file contents. $ARGV[0] is the first command-line parameter.
    # We print out the matched text if we have a match, or nothing if we don't.
    [/tmp]> cat regex.pl
    $val = $ARGV[0];
    print ($val =~ m/^[&':,\/\-().#";A-Za-z0-9]+$/g);
    print "\n";
    

    Some examples:

    # Have to escape ( and & in the shell, since they have meaning.
    [/tmp]> perl regex.pl a\(bc\&
    a(bc&
    
    [/tmp]> perl regex.pl abbb%c
    
    
    [/tmp]> perl regex.pl abcx
    abcx
    
    [/tmp]> perl regex.pl 52
    52
    
    [/tmp]> perl regex.pl 5%2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty new to regular expressions. I have a requirement to replace spaces in
I'm not sure how do this, as I'm pretty new to regular expressions, and
I'm pretty new to my company (2 weeks) and we're starting a new platform
I'm a pretty new C# and .NET developer. I recently created an MMC snapin
I'm pretty new to the idea of recursion and this is actually my first
I am pretty new to php, but I am learning! I have a simple
I am pretty new to VB.NET - and I'm struggling to convert the signature
I'm pretty new to JSF and the many many related technologies out there. I'm
I'm pretty new to the C++ build flow, and I'm thinking of switching to
I'm pretty new to the Spring Framework, I've been playing around with it and

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.