- For the purpose of exemplifying the answer, I replaced
String1/String2
adding String3 :
String1 --> pizza
String2 --> chocolate
String3 --> soda pop
- What suits me for this kind of task:
$i=@('.+(?=.*\bpizza\b)(?=.*\brefrigerante\b)(?=.*\bchocolate\b).*'); gc .\log.txt | sls $i
- Some examples diversified applied in the various searches in
PowerShell
# -------------------------------------------------------------------- #
# listar o conteúdo do arquivo: .\log.txt #
gc .\log.txt # linha 0 - 8 #
# -------------------------------------------------------------------- #
# qualquer ocorrência de pizza, ou, refrigerante, ou chocolate #
gc .\log.txt | sls '(pizza|refrigerante|chocolate)' # linha 1 - 8 #
gc .\log.txt | sls 'pizza','refrigerante','chocolate' # linha 1 - 8 #
gc .\log.txt | sls 'chocolate','refrigerante','pizza' # linha 1 - 8 #
gc .\log.txt | sls 'refrigerante','chocolate','pizza' # linha 1 - 8 #
gc .\log.txt | sls '(?:pizza|refrigerante|chocolate)' # linha 1 - 8 #
gc .\log.txt | sls '(?:refrigerante|chocolate|pizza)' # linha 1 - 8 #
gc .\log.txt | sls '(?:chocolate|refrigerante|pizza)' # linha 1 - 8 #
# -------------------------------------------------------------------- #
# chocolate | pizza | refrigerante numa ordem de ocorrências definida #
gc .\log.txt | sls 'chocolate.+pizza.+refrigerante' # linha - 7 #
gc .\log.txt | sls 'refrigerante.+chocolate.+pizza' # linha - 8 #
# -------------------------------------------------------------------- #
# pizza + refrigerante + chocolate em qualquer ordem na mesma linha #
$i=@('.+(?=.*\bpizza\b)(?=.*\brefrigerante\b)(?=.*\bchocolate\b).*') #
gc .\log.txt | sls $i # linha 7 - 8 #
# -------------------------------------------------------------------- #
- To fulfill any search among more than one string
- To meet any search in a certain order of occurrence of strings
- To meet any search in no certain order of occurrence of strings
- Contents of the archive: .\log.txt (line 0 - 8)
0) frase sem torta de sanduíche com mandioquinha
1) frase com pizza de --------- com ------------
2) frase com ----- de chocolate com ------------
3) frase com ----- de --------- com refrigerante
4) frase com ----- de chocolate com refrigerante
5) frase com pizza de --------- com refrigerante
6) frase com pizza de chocolate com ------------
7) frase com chocolate de pizza com refrigerante
8) frase com refrigerante de chocolate com pizza
- To any occurrence of pizza, or soda pop or chocolate on the line
gc .\log.txt | sls '(pizza|refrigerante|chocolate)' # linha 1 - 8 #
gc .\log.txt | sls 'pizza','refrigerante','chocolate' # linha 1 - 8 #
gc .\log.txt | sls 'chocolate','refrigerante','pizza' # linha 1 - 8 #
gc .\log.txt | sls 'refrigerante','chocolate','pizza' # linha 1 - 8 #
gc .\log.txt | sls '(?:pizza|refrigerante|chocolate)' # linha 1 - 8 #
gc .\log.txt | sls '(?:refrigerante|chocolate|pizza)' # linha 1 - 8 #
gc .\log.txt | sls '(?:chocolate|refrigerante|pizza)' # linha 1 - 8 #
1) frase com pizza de --------- com ------------
2) frase com ----- de chocolate com ------------
3) frase com ----- de --------- com refrigerante
4) frase com ----- de chocolate com refrigerante
5) frase com pizza de --------- com refrigerante
6) frase com pizza de chocolate com ------------
7) frase com chocolate de pizza com refrigerante
8) frase com refrigerante de chocolate com pizza
- To the occurrences predefined of strings on the line:
- Obeys the defined order of occurrences: chocolate + pizza + soda
gc .\log.txt | sls 'chocolate.+pizza.+refrigerante'
7) frase com chocolate de pizza com refrigerante
- To the occurrences predefined of strings on the line:
- Obeys the defined order of occurrences: soda + chocolate + pizza
gc .\log.txt | sls 'refrigerante.+chocolate.+pizza'
8) frase com refrigerante de chocolate com pizza
- To multiple strings in any order of occurrence on the line:
# pizza + refrigerante + chocolate em qualquer ordem na mesma linha #
$i=@('.+(?=.*\bpizza\b)(?=.*\brefrigerante\b)(?=.*\bchocolate\b).*') #
gc .\log.txt | sls $i # linha 7 - 8 #
7) frase com chocolate de pizza com refrigerante
8) frase com refrigerante de chocolate com pizza
For more information on regex at powershell/en
– It Wasn't Me