reg expressions Multiple search



  • hi all, I need to find, using regular expressions in notepad ++, all words preceded by the dollar sign “$” and a space starting with “a” and / or “b” and / 0 “bah” .
    I tried with the following expression but it just finds all combinations of a and b but it doesn’t find “bah”.

    \$((\s)+)((a|b|bah)+)
    

    Any suggestions? thank you



  • @claudio-pergolin

    Put your bah as an earlier alternative?

    Maybe \$((\s)+)((bah|a|b)+)



  • yes, weird thing is that if “bah” I put it as the first option that is “\ $ ((\ s) +) ((blah | a | b) +)” is found.
    How is it possible?
    Hello and thanks



  • @claudio-pergolin said in reg expressions Multiple search:

    yes, weird thing is that if “bah” I put it as the first option that is “\ $ ((\ s) +) ((blah | a | b) +)” is found.

    Can’t tell what that means.
    Please provide examples.



  • @claudio-pergolin said in reg expressions Multiple search:

    How is it possible?

    Because the order of search terms matters in alternations (OR conditions). The problem with searching for b then a then bah is that when it runs across b it says "I match on b", then it runs across a and says "I match on a" – and it’s already matched the condition of one or more instances of a, b, and bah. It never backtracks to try to find bah because ba was already matching and meeting the requirements of your regex. On the other hand, if bah is listed before the others as bah|a|b, then it tries to match bah before trying either b or a, and then it will match the longer word. The general rule of thumb in alternations is if more than one alternation might match the same text, you need to put the longer or more important alternation first.



  • @Alan-Kilborn said in reg expressions Multiple search:

    Non so cosa significhi.
    Fornisci esempi.

    Se nella mia espressione di ricerca faccio occupare a “bah” la prima alternanza, invece dell’ultima posizione ( vedi primo mio post), quindi:

    \$((\ s)+)((bah|a|b)+)
    

    In tal caso mi trova anche la parola che incomincia con “$ bah”



  • @claudio-pergolin

    Posting in your native language isn’t going to help me understand, it’s just going to make me translate it to English – if I feel like it – when that is something you should do before posting on an English language forum.

    Probably the part that confused me the most was not anything to do with language, it was that you suddenly introduced blah instead of bah into it.

    Anyway, I think probably Peter’s reply cleared up any confusion for you.
    Cheers!



  • @Alan-Kilborn said in reg expressions Multiple search:

    @claudio-pergolin

    Posting in your native language isn’t going to help me understand, it’s just going to make me translate it to English – if I feel like it – when that is something you should do before posting on an English language forum.

    Probably the part that confused me the most was not anything to do with language, it was that you suddenly introduced blah instead of bah into it.

    Anyway, I think probably Peter’s reply cleared up any confusion for you.
    Cheers!

    sorry but with chrome that translates automatically, I forgot to translate it directly into English …sorry!


Log in to reply