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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:55:02+00:00 2026-05-11T05:55:02+00:00

I was trying to do a regex for someone else when I ran into

  • 0

I was trying to do a regex for someone else when I ran into this problem. The requirement was that the regex should return results from a set of strings that has, let’s say, ‘apple’ in it. For example, consider the following strings:

'I have an apple' 'You have two Apples' 'I give you one more orange'

The result set should have the first two strings.

The regex(es) I tried are:

/[aA]pple/ and /[^a-zA-Z0-9][aA]pple/

The problem with the first one is that words like ‘aapple’, ‘bapple’, etc (ok, so they are meaningless, but still…) test positive with it, and the problem with the second one is that when a string actually starts with the word ‘apple’, ‘Apples and oranges’, for example, it tests negative. Can someone explain why the second regex behaves this way and what the correct regex would be?

  • 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. 2026-05-11T05:55:03+00:00Added an answer on May 11, 2026 at 5:55 am
    /(^.*?\bapples?\b.*$)/i 

    Edit: The above will match the entire string containing the word ‘apples’, which I thought is what you were asking for. If you are just trying to see if the string contains the word, the following will work.

    /\bapples?\b/i 

    The regex(es) I tried are:

    /[aA]pple/ and /[^a-zA-Z0-9][aA]pple/

    The first one just checks for the existence of the following characters, in order: a-p-p-l-e, regardless of what context they are used in. The \b, or word-boundary character, matches any spot where a non-word character and a word character meet, ala \W\w.

    The second one is trying to match other characters before the occurrance of a-p-p-l-e, and is essentially the same as the first, except it requires other characters in front of it.

    The one I answered with works like following. From the beginning of the string, matches any characters (if they exist) non-greedily until it encounters a word boundary. If the string starts with apple, the beginning of a string is a word-boundary, so it still matches. It then matches the letters a-p-p-l-e, and s if it exists, followed by another word boundary. It then matches all characters to the end of the string. The /i at the end means it’s case-insensitive, so ‘Apple’, ‘APPLE’, and ‘apple’ are all valid.

    If you have the time, I would highly recommend walking through the tutorial at http://regular-expressions.info. It really goes in-depth and talks about how the regular expression engines match different expressions, it helped me a ton.

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

Sidebar

Related Questions

Im trying to craft a regex that only returns <link> tag hrefs Why does
I'm trying to write a regex function that will identify and replace a single
I'm trying to write a regex that will parse out the directory and filename
I'm trying to get a regex that will match: somefile_1.txt somefile_2.txt somefile_{anything}.txt but not
I'm trying to create a Regex usuable in C# that will allow me to
I'm trying to learn RegEx in Ruby, based on what I'm reading in The
I've been trying to figure out a regex to allow me to search for
I'm trying to put together a comprehensive regex to validate phone numbers. Ideally it
I'm trying to create a Regex to block all < and > in a
I am trying to implement string unescaping with Python regex and backreferences, and it

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.