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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:07:36+00:00 2026-05-27T11:07:36+00:00

I tried this code: public static void main(String[] args) throws Exception { String regexp

  • 0

I tried this code:

public static void main(String[] args) throws Exception {
        String regexp = "[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)*(\\.)[a-zA-Z]+";    

        String text1 = "my.name-here@my.domain-here.ext";
        String text2 = "my.name-here@m@y.domain-here.ext";
        String text3 = "@domain-here.ext";
        String text4 = "my.name-here@";
        String text5 = "my.name-here@domain-here";
        String text6 = ".my.name-here@my.domain-here.ext";
        String text7 = "my.name-here.@my.domain-here.ext";
        String text8 = "my.name-here@.my.domain-here.ext";
        String text9 = "my.name-here@my.domain-here.ext.";
        String text10 = "my.na me-here@my.domain-here.ext";
        String text11 = "my.name-here@my.dom ain-here.ext";
        String text12 = "my..name-here@my.domain-here.ext";
        String text13 = "my.name-here@my..domain-here.ext";

        RE re = new RE(regexp);
        System.out.println(re.match(text1));
        System.out.println(re.match(text2));
        System.out.println(re.match(text3));
        System.out.println(re.match(text4));
        System.out.println(re.match(text5));
        System.out.println(re.match(text6));
        System.out.println(re.match(text7));
        System.out.println(re.match(text8));
        System.out.println(re.match(text9));
        System.out.println(re.match(text10));
        System.out.println(re.match(text11));
        System.out.println(re.match(text12));
        System.out.println(re.match(text13));

        System.out.println(Pattern.matches(regexp, text1));
        System.out.println(Pattern.matches(regexp, text2));
        System.out.println(Pattern.matches(regexp, text3));
        System.out.println(Pattern.matches(regexp, text4));
        System.out.println(Pattern.matches(regexp, text5));
        System.out.println(Pattern.matches(regexp, text6));
        System.out.println(Pattern.matches(regexp, text7));
        System.out.println(Pattern.matches(regexp, text8));
        System.out.println(Pattern.matches(regexp, text9));
        System.out.println(Pattern.matches(regexp, text10));
        System.out.println(Pattern.matches(regexp, text11));
        System.out.println(Pattern.matches(regexp, text12));
        System.out.println(Pattern.matches(regexp, text13));
    }

Only the first one must be right but… org.apache.regexp.RE does something wrong. Any solution? Thanks a lot. I have to do it with org.apache.regexp.RE obligatory.

Update: Pattern do matches right (all false except the first one), RE say someone String are true but they isn’t.

  • 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-27T11:07:37+00:00Added an answer on May 27, 2026 at 11:07 am

    Your expression does not state that it must match the entire input and thus I assume within my.name-here@m@y.domain-here.ext Apache Regexp matches the m@y.domain-here.ext part (although I don’t know Apache RegexP that well and it is retired, btw).

    Wrap your regex with ^ and $ to make it match the entire input.

    From the JavaDoc on Matcher#matches() (Pattern.matches(...) calls that method as you can see from its JavaDoc):

    Attempts to match the entire region against the pattern

    Edit

    I just tested your expression in the RegexP applet and it seems like you have to escape the literal - in your character classes (which is good practice anyways). This expression seems to work in RegexP:

    "^[\\w\\-]+(\\.[\\w\\-]+)*@[\\w\\-]+(\\.[\\w\\-]+)*(\\.)[a-zA-Z]+$"
    

    Btw, you might want to add non-capturing groups to optimize the expression a bit, i.e. instead of (\\.) you’d write (?:\\.) etc.

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

Sidebar

Related Questions

I tried this aproach without any success the code I'm using: // File name
Why does the following program throw an exception? public class MainClass{ public static void
Here's the code: package testpack; import java.io.*; public class InputStreamReadDemo { private void readByte()
A BufferedInputStream that I have isn't marking correctly. This is my code: public static
I tried this code to open a file in Python: f = open("/Desktop/temp/myfile.txt","file1") It
i have tried this code to redirect a php page.but it s not working
I am trying to enable mod_deflate. I have Apache 2.0+ and tried this code
i've tried using this code and this to make a random quote generator, but
How do I check if a textarea contains nothing? I tried with this code:
Is it possible to change PowerPacks.LineShape smoothingMode? I tried to use this code(a class

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.