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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:36:43+00:00 2026-06-18T05:36:43+00:00

The regular expression, String regex = [0-9a-z]+@[0-9a-z]+.+[0-9a-z]; , is used for testing a email

  • 0

The regular expression, "String regex = "[0-9a-z]+@[0-9a-z]+.+[0-9a-z]";" , is used for testing a email validation. Basically, im trying to make it so that an email will only match this patter if the email begins with a string of alphanumeric chars, followed by 1 @ symbol, followed by another string of alphanumeric chars, followed by 1 ., and then finally a string of alphanumeric chars. Whats failing is that when i enter an email without a string of alphanumerics after the last ., the program will still match with the regex string. How do i make it so that there MUST be another string of alphanumerics after the .? The whole code is:

import java.util.Scanner;
import java.util.regex.*;

public class Regex
{   
    public static void main (String[]args){

        Scanner input = new Scanner(System.in);
        System.out.println("Please enter your Email");
        String mail = input.nextLine();

        String regex = "[0-9a-z]+@[0-9a-z]+.+[0-9a-z]";

        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(mail);

        if(m.find()) {
            System.out.println("VALID");
        } else {
            System.out.println("INVALD");
        }
    }
}
  • 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-18T05:36:44+00:00Added an answer on June 18, 2026 at 5:36 am

    A slightly better regex would include start of line ^ and end of line $ anchors.

    Otherwise it will only need to match a single instance of a valid email in the string and it will pass. Also, instead of the plus sign to indicate 1 or more, you could restrict it to 2 to 4 characters by adding {2,4}. Without these in place something like

    myemail@gmail.com@thisIsOdd.helloworld.anythingelse

    will erroneously be valid.

    String regex = "^[0-9a-z]+@([0-9a-z]+[.])+[0-9a-z]{2,4}$";

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

Sidebar

Related Questions

I need a regular expression that will match any string containing at most 2
I want a regular expression that validate a string that allow only numbers and
In javascript you can match regular expression with regex(string) syntax. However the syntax isn't
I'm trying to create a string from a regular expression. I noticed that in
I have these variables: boost::regex re //regular expression to use std::string stringToChange //replace this
i want a regular expression to validate string to have only text,operators and these
What regular expression can I use (if any) to validate that a given string
I want to use regular expression same way as string.Format. I will explain I
I am trying to match words using a regular expression, but sadly the word
I have a regular expression that works fine for me when used in ASP.NET

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.