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
-
-
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
thena
thenbah
is that when it runs acrossb
it says “I match onb
”, then it runs acrossa
and says “I match ona
” – and it’s already matched the condition of one or more instances of a, b, and bah. It never backtracks to try to findbah
becauseba
was already matching and meeting the requirements of your regex. On the other hand, ifbah
is listed before the others asbah|a|b
, then it tries to matchbah
before trying eitherb
ora
, 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”
-
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 ofbah
into it.Anyway, I think probably Peter’s reply cleared up any confusion for you.
Cheers! -
@Alan-Kilborn said in reg expressions Multiple search:
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 ofbah
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!