1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Regex help

Discussion in 'HTML, Graphics & Programming' started by A[L]C, May 3, 2018.

  1. A[L]C

    Soldato

    Joined: Oct 18, 2002

    Posts: 7,448

    Location: Maidenhead

    Hi all,

    Looking for some help with regex please. My example data:

    a) ifvmsqltestx1
    b) ifvmdevx1
    c) ifvmx1

    I need 3 statements

    1) returns when the string "test" is found e.g. only a
    2) returns when the string "dev" is found e.g. only b
    3) returns when neither the string "test" nor "dev" is found e.g. only c

    Many thanks in advance
    Alc
     
    Last edited: May 3, 2018
  2. touch

    Capodecina

    Joined: Oct 28, 2006

    Posts: 10,278

    Location: Sufferlandria

    The regex would just be the string your searching for. If both tests 1 and 2 return false then you know the string doesnt contain either word so there's no need to test it again.

    I would just use indexOf(string) in this case, you don't need the complexity that regex can give you (and, depending on your situation, indexOf might run faster anyway).
     
  3. A[L]C

    Soldato

    Joined: Oct 18, 2002

    Posts: 7,448

    Location: Maidenhead

    Hi thanks for the reply. I am using a built in regex function, not developing so I have to use regex. 1 and 2 are fine as I just use "test" or "dev", but 3 does not work as the regex has to match the value.
     
  4. Spunkey

    Capodecina

    Joined: Oct 18, 2002

    Posts: 13,027

    Location: The land of milk & beans

    Which language are you writing the Regex in?
     
  5. A[L]C

    Soldato

    Joined: Oct 18, 2002

    Posts: 7,448

    Location: Maidenhead

    It's an SSMS plugin - apparently Any .Net regular expression is valid.

    I think I may have it with (?!test)|(?!dev) - does that sound right?
     
  6. SimonCHere

    Wise Guy

    Joined: Jun 24, 2008

    Posts: 1,106

    No really. try this:

    ^((?!dev|test).)*$
     
  7. A[L]C

    Soldato

    Joined: Oct 18, 2002

    Posts: 7,448

    Location: Maidenhead

    Thanks :) What's the difference?
     
  8. SimonCHere

    Wise Guy

    Joined: Jun 24, 2008

    Posts: 1,106