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 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

Ask A Question

Stats

  • Questions 90k
  • Answers 90k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No, basically. If you want to use the existing DataContractSerializer,… May 11, 2026 at 6:06 pm
  • Editorial Team
    Editorial Team added an answer With the Entity Framework most of the time SaveChanges() is… May 11, 2026 at 6:06 pm
  • Editorial Team
    Editorial Team added an answer [window setContentAspectRatio:NSMakeSize(width, height)] More info: Apple's documentation, NSWindow class reference May 11, 2026 at 6:06 pm

Related Questions

I'm trying to parse the title tag in an RSS 2.0 feed into three
I am writing a Perl script that is searching for a term in large
I have a RegEx that is working for me but I don't know WHY
I'm trying to write a regex that will parse out the directory and filename

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.