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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:45:56+00:00 2026-05-22T19:45:56+00:00

I’ve searched for a while how to use logical operation AND in regular expressions

  • 0

I’ve searched for a while how to use logical operation AND in regular expressions in Java, and have failed.
I’ve tried to do as recommended in similar topic:

(?=match this expression)(?=match this too)(?=oh, and this)

and it doesn’t work. Even simple examples with ?= returns false:

String b = "aaadcd";
System.out.println(b.matches("(?=aa.*)"));

Also I’ve read that (expression X)(expression Y) should work like X AND Y, but it works like X OR Y.
What am I doing wrong?

Added:
Tried to add .* in the end. Still don’t work.
For a example:

[2-9]?[0-9]{5,9}||1[2-9][0-9]{1,2}||120[0-9]{1,1}||119[0-9] = X – return false if number is less than 1190

[0-9]{1,3}||1[0-0][0-9]{1,2}||11[0-8][0-9]{1,1}||119[0-2] = Y – return false if number is greater than 1992.

String a = "1189";
a.matches(X) // return false
a.mathes(Y)  // return true
a.matches((?=X)(?=Y).*) // return true, but should return false.

Added:
Yep, my regexp is not correct. My bad. The problem solved. Thank everyone very much!

  • 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-22T19:45:57+00:00Added an answer on May 22, 2026 at 7:45 pm

    I think what you need is (?=X)Y

    • (?=X) matches X, without consuming it (zero-width)
    • Y and matches Y

    The main problem: X and Y are wrong, they should be (assuming 4 digits):

    X: 119[0-9]|1[2-9][0-9]{2}|[2-9][0-9]{3}

    • 1190-1199, or
    • 1200-1999, or
    • 2000-9999

    Y: 1[0-8][0-9]{2}|19[0-8][0-9]|199[0-2]

    • 1000-1899, or
    • 1900-1980, or
    • 1990-1992

    Here a test code:

    // X - return false if number is less than 1190
    String X = "119[0-9]|1[2-9][0-9]{2}|[2-9][0-9]{3}"; 
    
    // Y - return false if number is greater than 1992.
    String Y = "1[0-8][0-9]{2}|19[0-8][0-9]|199[0-2]";
    
    String pattern = "(?=" + X + ")" + Y;
    
    String values = "1000 1100 1180 1189 1190 1191 1199 1200 1290 1900 1980 1989 " +
                    "1990 1991 1992 1993 1999 2000 3000 2991 9999";
    for (String string : values.split(" ")) {
        System.out.printf("\"%s\" %s%n", string, string.matches(pattern));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.