Match a string pattern in Regular expression that does not contain a particular string.

Posted on 2009-02-19
Last Modified: 2012-05-06
Hi everyone,

I m searching solution to the problem

I have to match only those strings that don't end with "es" and "ies" using Regex.

plz give me a solution ASAP.

thanx in advance.
Question by:ASINGH1974
    LVL 42

    Accepted Solution

    LVL 16

    Expert Comment

    by:Peter Kwan
    Can you do the negation in your programming language? What I mean is you test your search string and find if the string ends with "es" (actually "ies" is a case of "es"), then negate the result (i.e. return true only if the string does not end with "es"/"ies")
    LVL 16

    Expert Comment

    by:Peter Kwan
    If the above comment is ok for you, then the regular expression to test whether a string ends with "es" is:


    Author Comment

    Actually I am using a dynamic pattern check for matching the string.

    foreach(string patternString in db.getRegexPatterns())
          if(Regex.IsMatch(inputString, patternString))
           { //-------}

    different inputs will match with different patterns.
    I want that "" or "" will match but
    "" and "" will not be a valid input.

    also, I cant use it at the code side in my program, I hav to use it only in patternString which is stored in database.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    I have been reconstructing a PHP-based application that has grown into a full blown interface system over the last ten years by a developer that has now gone into business for himself building websites. I am not incredibly fond of writing PHP code o…
    As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now