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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:57:41+00:00 2026-06-13T16:57:41+00:00

So far I’ve been using ^[a-zA-Z]+( [a-zA-z]+)*$ to make sure user input Has no

  • 0

So far I’ve been using ^[a-zA-Z]+( [a-zA-z]+)*$ to make sure user input Has no space in the beginning and the end and not to accept numbers or special characters and only to accept alphabetical characters.

I looked at the regex list online and in my texts I can’t seem to formulate one under these conditions for a recursive palindrome program:

  • Accepts strings containing upper case or lower case characters.
  • Accepts punctuation, and single spaced blanks.

I don’t think I’ll need a regex for the following after validation, but if there is I’d like to know what it is.

  • After validation upper case letters must be converted to lower case.
  • The punctuation and spaces are to be ignored.
  • 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-13T16:57:43+00:00Added an answer on June 13, 2026 at 4:57 pm

    If I understand you correctly, you want to create a recursive palindrome checker that employs regular expressions, in Java. I’m interested in learning Java, so I gave it a shot as my own sort of “homework problem,” although it is probably yours too.

    import java.lang.*;
    import java.util.*;
    import java.util.regex.*;
    
    class Main
    {
        public static boolean recursivePalindrome(String str)
        {
            // We need two patterns: one that checks the degenerate solution (a
            // string with zero or one [a-z]) and one that checks that the first and
            // last [a-z] characters are the same. To avoid compiling these two
            // patterns at every level of recursion, we compile them once here and
            // pass them down thereafter.
            Pattern degeneratePalindrome = Pattern.compile("^[^a-z]*[a-z]?[^a-z]*$", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
            Pattern potentialPalindrome  = Pattern.compile("^[^a-z]*([a-z])(.*)\\1[^a-z]*$", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
            return recursivePalindrome(str, degeneratePalindrome, potentialPalindrome);
        }
    
        public static boolean recursivePalindrome(String str, Pattern d, Pattern p)
        {
            // Check for a degenerate palindrome.
            if (d.matcher(str).find()) return true;
    
            Matcher m = p.matcher(str);
    
            // Check whether the first and last [a-z] characters match.
            if (!m.find()) return false;
    
            // If they do, recurse using the characters captured between.
            return recursivePalindrome(m.group(2), d, p);
        }
    
        public static void main (String[] args) throws java.lang.Exception
        {
            String str1 = "A man, a plan, a canal... Panama!";
            String str2 = "A man, a pan, a canal... Panama!";
    
            System.out.println(str1 + " : " + Boolean.toString(recursivePalindrome(str1)));
            System.out.println(str2 + " : " + Boolean.toString(recursivePalindrome(str2)));
        }
    }
    

    The output is:

    A man, a plan, a canal... Panama! : true
    A man, a pan, a canal... Panama! : false
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So far I have not been able to find an answer, but I wanted
So far everytime i use to make a select query using pdo, i used
So far, the bundles I've used for Symfony2 has been installed modifying the deps
So far I have been able to compile my Java programs in Linux using
So far I have been using in tutorials, examples and sample code only packages
So far, my experience in web design has been with very small scale sites
So far I've been setting up redirects for single pages on my ASP.NET site
So far I have only been updated a view from within its controller. I
As far as I can see this is not the case, however, I thought
As far as my understanding after reading and researching, the purpose of using salt

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.