Ir para conteúdo
Fórum Script Brasil
  • 0

Re


Ale

Pergunta

// não sou mt bom em ingles... algm poderia dar um help:

4.2.2 Matching vs Searching

Python offers two different primitive operations based on regular expressions: match and search. If you are accustomed to Perl's semantics, the search operation is what you're looking for. See the search() function and corresponding method of compiled regular expression objects.

Note that match may differ from search using a regular expression beginning with "^": "^" matches only at the start of the string, or in MULTILINE mode also immediately following a newline. The ``match'' operation succeeds only if the pattern matches at the start of the string regardless of mode, or at the starting position given by the optional pos argument regardless of whether a newline precedes it.

re.compile("a").match("ba", 1) # succeeds

re.compile("^a").search("ba", 1) # fails; 'a' not at start

re.compile("^a").search("\na", 1) # fails; 'a' not at start

re.compile("^a", re.M).search("\na", 1) # succeeds

re.compile("^a", re.M).search("ba", 1) # fails; no preceding \n

// tipo... to procurando saber como faco uma busca

// por string num arquivo...

// vlw e flwz...

Link para o comentário
Compartilhar em outros sites

2 respostass a esta questão

Posts Recomendados

  • 0

Se a string a ser procurada não exigir expressões regulares, você pode utilizar apenas o método find() da str. Exemplo:

print file('arquivo.txt').read().find('string a ser procurada')

Se o resultado for maior ou igual a 0 a string foi encontrada e o valor retornado refere-se a posição da mesma. Caso contrário (um valor negativo), a string não foi encontrada.

Abraços,

Graymalkin

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...