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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:30:16+00:00 2026-05-18T10:30:16+00:00

I need logical AND in regex. something like jack AND james agree with following

  • 0

I need logical AND in regex.

something like

jack AND james

agree with following strings

  • ‘hi jack here is james‘

  • ‘hi james here is jack‘

  • 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-18T10:30:17+00:00Added an answer on May 18, 2026 at 10:30 am

    You can do checks using positive lookaheads. Here is a summary from the indispensable regular-expressions.info:

    Lookahead and lookbehind, collectively called “lookaround”, are
    zero-length assertions…lookaround actually matches characters, but
    then gives up the match, returning only the result: match or no match.
    That is why they are called “assertions”. They do not consume
    characters in the string, but only assert whether a match is possible
    or not.

    It then goes on to explain that positive lookaheads are used to assert that what follows matches a certain expression without taking up characters in that matching expression.

    So here is an expression using two subsequent postive lookaheads to assert that the phrase matches jack and james in either order:

    ^(?=.*\bjack\b)(?=.*\bjames\b).*$
    

    Test it.

    The expressions in parentheses starting with ?= are the positive lookaheads. I’ll break down the pattern:

    1. ^ asserts the start of the expression to be matched.
    2. (?=.*\bjack\b) is the first positive lookahead saying that what follows must match .*\bjack\b.
    3. .* means any character zero or more times.
    4. \b means any word boundary (white space, start of expression, end of expression, etc.).
    5. jack is literally those four characters in a row (the same for james in the next positive lookahead).
    6. $ asserts the end of the expression to me matched.

    So the first lookahead says "what follows (and is not itself a lookahead or lookbehind) must be an expression that starts with zero or more of any characters followed by a word boundary and then jack and another word boundary," and the second look ahead says "what follows must be an expression that starts with zero or more of any characters followed by a word boundary and then james and another word boundary." After the two lookaheads is .* which simply matches any characters zero or more times and $ which matches the end of the expression.

    "start with anything then jack or james then end with anything" satisfies the first lookahead because there are a number of characters then the word jack, and it satisfies the second lookahead because there are a number of characters (which just so happens to include jack, but that is not necessary to satisfy the second lookahead) then the word james. Neither lookahead asserts the end of the expression, so the .* that follows can go beyond what satisfies the lookaheads, such as "then end with anything".

    I think you get the idea, but just to be absolutely clear, here is with jack and james reversed, i.e. "start with anything then james or jack then end with anything"; it satisfies the first lookahead because there are a number of characters then the word james, and it satisfies the second lookahead because there are a number of characters (which just so happens to include james, but that is not necessary to satisfy the second lookahead) then the word jack. As before, neither lookahead asserts the end of the expression, so the .* that follows can go beyond what satisfies the lookaheads, such as "then end with anything".

    This approach has the advantage that you can easily specify multiple conditions.

    ^(?=.*\bjack\b)(?=.*\bjames\b)(?=.*\bjason\b)(?=.*\bjules\b).*$
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to do some logical comparison and return a boolean answer. Here is
I need to use one logical PGM based multicast address in application while enable
I have a need to evaluate user-defined logical expressions of arbitrary complexity on some
Need help. It may be weird. First activity has listview(like lazyadapter) once i click
Need to locate the following pattern: The letter I followed by a space then
Hello I want to make something like a meta language which gets parsed and
I need to test a logical expression held in a string to see if
I need to convert integer value into hexadecimal. I have done with some logical,
i have a bit of logical problem here. I have a catalog of products
I need determind size of a logical volume and print it. GetDiskFreeSpaceEx is returning

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.