RegEx question?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas T. Veldhouse

    RegEx question?

    I am looking for a regular expression that will match a string that contains
    the word "clamp" but will not match if the string also contains the word
    "arch".

    So,

    No Match: "Arch Clamp" "ArchClamp" "archclamp" "yada archie clamp"

    Match: "Clamp" "sring clamp" "deck clamp"

    Is there an easy way to do this in a single expression?

    Thanks in advance.

    --
    Thomas T. Veldhouse
    Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1


  • gpg

    #2
    Re: RegEx question?


    Thomas T. Veldhouse wrote:
    I am looking for a regular expression that will match a string that contains
    the word "clamp" but will not match if the string also contains the word
    "arch".
    >
    So,
    >
    No Match: "Arch Clamp" "ArchClamp" "archclamp" "yada archie clamp"
    >
    Match: "Clamp" "sring clamp" "deck clamp"
    >
    Is there an easy way to do this in a single expression?
    >
    Thanks in advance.
    >
    --
    Thomas T. Veldhouse
    Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1
    Maybe something like this

    (?i)(?-imsnx)^((?!(.*a rch.*)).*(clamp ))$

    There is a fantastic tool called Expresso that I use to develop and
    analyse regular expressions - it is even free. Check out ultrapico.com

    GPG

    Comment

    • Thomas T. Veldhouse

      #3
      Re: RegEx question?

      gpg <gpggpg@hotmail .comwrote:
      >
      Maybe something like this
      >
      (?i)(?-imsnx)^((?!(.*a rch.*)).*(clamp ))$
      >
      Thanks! Very very close. I had to remove the trailing $ as "clamps" is also
      a match.
      There is a fantastic tool called Expresso that I use to develop and
      analyse regular expressions - it is even free. Check out ultrapico.com
      >
      Tool looks great! I haven't given it a try as of yet, but I did open the
      tutorial. I think there is a risk that my Regex skills might actually
      decrease after this ;-)

      --
      Thomas T. Veldhouse
      Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1


      Comment

      • gpg

        #4
        Re: RegEx question?

        No problem!

        Expresso is extremely handy plus is will generate c# code for you based
        on the regex that you develop. Just the ability to run test matches
        and build expressions makes this app a must in my toolbox.

        GPG

        Thomas T. Veldhouse wrote:
        gpg <gpggpg@hotmail .comwrote:

        Maybe something like this

        (?i)(?-imsnx)^((?!(.*a rch.*)).*(clamp ))$
        >
        Thanks! Very very close. I had to remove the trailing $ as "clamps" is also
        a match.
        >
        There is a fantastic tool called Expresso that I use to develop and
        analyse regular expressions - it is even free. Check out ultrapico.com
        >
        Tool looks great! I haven't given it a try as of yet, but I did open the
        tutorial. I think there is a risk that my Regex skills might actually
        decrease after this ;-)
        >
        --
        Thomas T. Veldhouse
        Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1

        Comment

        Working...