How to search words which not contain the search pattern?

How to search words which not contain the search pattern?

1
NewbieNewbie
1

    Mar 12, 2008#1

    Hello,

    I have a file containing following lines:

    AbcTempSpeed
    XyzTempSpeed
    _XyzSpeed
    _ZeroTempSpeed
    AbcSpeed
    MedianTemSpeed
    _AbcTempPressure

    I need to find all words which do not include the pattern 'Temp'
    ('_XyzSpeed' , 'AbcSpeed' and 'MedianTemSpeed' in the above example).

    Is this possible using UE regular expressions?

    Thanks for any hint.
    Regards
    Sergeant

    236
    MasterMaster
    236

      Mar 12, 2008#2

      Hi Sergeant,

      it is possible if you have UE V12 or higher (which you didn't tell us although the Readme forum topic is quite explicit about this).

      The following Perl style regex will match a word that doesn't contain the string Temp:

      Code: Select all

      \b(?:(?!Temp)\w)+\b
      (courtesy of RegexBuddy)

      HTH,
      Tim

      119
      Power UserPower User
      119

        Mar 12, 2008#3

        That's clever, Tim. At first I thought that the (?:) was superfluous but I see now that you're using it to apply the negative look-ahead before each character.

        236
        MasterMaster
        236

          Mar 12, 2008#4

          I'd love to take credit for it, but I grokked it from RegexBuddy. :)

          22
          Basic UserBasic User
          22

            Mar 20, 2008#5

            I could be wrong, but I think the ?: just creates a non-capturing group. It will work without it, but you'll waste resources saving the capture. The iteration is caused by having the + outside the parenthesis rather than inside. If you put it inside
            i.e.\b(?:(?!Temp)\w+)\b
            you will only avoid words that start with Temp.

            Nice job Tim,
            Jane

            119
            Power UserPower User
            119

              Mar 20, 2008#6

              Jane, You are correct. The ?: makes the grouping a non-capturing one. The grouping is the important thing, not the (lack of) capture.