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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:42:19+00:00 2026-06-16T11:42:19+00:00

How can I get my regular expression to match against just one condition exactly?

  • 0

How can I get my regular expression to match against just one condition exactly?

For example I have the following regular expression:

(\w+)(?=ly|es|s|y)

Matching the expression against the word “glasses” returns:

glasse

The correct match should be:

glass (match should be on 'es' rather than 's' as in the match above)

The expression should cater for any kinds of words such as:

films
lovely
glasses
glass

Currently the regular expression is matching the above words as:

film - correct
lovel - incorrect
glasse - incorrect
glas - incorrect

The correct match for the words should be:

film
love
glass
glass

The problem I am having at the moment is I am not sure how to adjust my regular expression to cater for either ‘s’ or ‘es’ exactly, as a word could contain both such as “glasses”.

Update

Thank you for the answers so far. I appreciate the complexity of stemming and the requirement of language knowledge. However in my particular case the words are finite (films,lovely,glasses and glass) and so therefore I will only ever encounter these words and the suffixes in the expression above. I don’t have a particular application for this. I was just curious to see if it was possible using regular expressions. I have come to the conclusion that it is not possible, however would the following be possible:

A match is either found or not found, for example match glasses but NOT glass but DO match films:

film (match) - (films)
glass (match) - (glasses)
glass (no match) - (glass)

What I’m thinking is if there is a way to match the suffix exactly against the string from the end. In the example above ‘es’ match glass(es) therefore the condition ‘s’ is discarded. In the case of glass (no match) the condition ‘s’ is discarded because another ‘s’ precedes it, it does not match exactly. I must admit I’m not 100% about this so my logic may seem a little shakey, it’s just an idea.

  • 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-06-16T11:42:20+00:00Added an answer on June 16, 2026 at 11:42 am

    The basic problem you’re having here is that the plus in

    (\w+)(?=ly|es|s|y)
    

    is greedy, and will grab as much as possible while still allowing the whole regex to match. You’ve not said exactly which flavour of regex you’re using but try

    (\w+?)(?=ly|es|s|y)
    

    +? means the same as + but is reluctant, matching as little as possible while still allowing the overall match to succeed.

    However this would still have the problem that it splits glass into glas and s. To handle this you’d need something like

    (\w+?)(?=ly|es|(?<!s)s|y)
    

    using negative look behind to prevent the s alternative from matching when preceded by another s.

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

Sidebar

Related Questions

I have the following regular expression: RegExp(http://www.amazon.com/([\\w-]+/)?(dp|gp/product)/(\\w+/)?(\\w{10})); Written in javascript. How can I get
I'm just wondering if it's possible to use one regular expression to match another,
I have a regular expression like this (much simplified): ^(ab)*$ And am matching against
I've got a regular expression that I'm trying to match against the following types
how can i get a regular expression to match whole words like grand and
Can anyone get me with the regular expression to strip multiline comments and single
How can I get content of a DIV using regular expression. What I need
If you have a regular link in HTML, you can get the value of
Say I have a regular expression like the following, but I loaded it from
I have the following regular expression for validating a file name: ^(([a-zA-Z]:|\)\)?(((.)|(..)|([^\/:*\?\|<>. ](([^\/:*\?\|<>. ])|([^\/:*\?\|<>]

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.