Regular Expression: how match a whole word?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tre MoR

    Regular Expression: how match a whole word?

    Regular Expression: how match a whole word?

    Hi All,
    First of all, I’d express all my gratitude to all whom will help me about this topic.
    I have a question about the Regular Expression Engine, the issue of mine is: Can I match an entire word using negative clauses?
    In English: I’ve a simple text as: “man,men,mon,mu n,car,cer,cir” and I’d match all the words which don’t contain in the first position the letter “m”, in the second “a” and in the third “n”. In this way:

    Text: “man,men,mon,mu n,car,cer,cir”
    Word To Search: all the words which don’t contain the letters [m][a][n] in the co respective positions.
    Pattern: “[^m][^a][^n]” (surely incorrect)

    If I use as Pattern [m][a][n], I’m able to find the word “man”, but how I could the reverse process?
    I’d like to retrieve all others words except this, is it possible?

    Sorry, for this kind of simple question, I tried several times before creating this post, but all the searches of mine about this topic have been unsatisfied.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    a very simple way of defining the RegEx just excludes the letter from the list: [a-ln-z][b-z][a-mo-z]. [^m][^a][^n] is not principally wrong, though it also matches non-letters.

    Comment

    • Tre MoR

      #3
      Hi Dormilich,

      first of all thank you for your reply!
      You're right I mean I could remove all the letters I'd remove, but just for better understand the Regular Expression Engine: how I'd search using negative cluases?

      In case I use a pattern like: [^m][^a][^n], instead of searching for all the words which don't contain the pattern "man", the engine searches for all the words which don't contain the letter "m: at the first position, the letter "a" at the second position and the letter "n" at the third one.
      The result using the precedent text example (“man,men,mon,m un,car,cer,cir” ) will be "an,en,on,un,ar ,cer,ci".

      I’d like to retrieve all others words except this, is it possible?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        The result using the precedent text example (“man,men,mon,m un,car,cer,cir” ) will be "an,en,on,un,ar ,cer,ci".
        no. given you use /[^m][^a][^n]/g on this string, you get: "an,", "en,", "on,", "un,", "ar,", "cer", ",ci". what you request is a 3 character match, thus your result is a couple of matching 3 characters strings.

        Comment

        Working...