Regex matching Python -


I want to write 3 different regular expressions first $ {any collection of characters} Should be detected, the second should find any order of $ {characters (any type of characters) , and the third one is either $ {any sequence of numbers} < / Code> or $ number of any number

Here's what I've tried:

  Import sys import os import re ncmd = 1 regular = re.compile ('$ {[az] *}') equals = re.compile ('$ {* [=] *}') #st After the triangle, after the string number = re.compile ('$ {(0-9) *} | $ (0-9) *') # $ {ANY_SEQUENCE_OF_DIGITS} or $ ANY_SEQUENCE_OF_DIGITS while (1): # print line Line = raw_input ("(% s) $"% Ncmd) if regular. Match (line): print "regular" print (oggetende (line [1:], '')) is equal to elif. Match (line): Print "Equals" Alif Number Match (line): print "number" and: print (line) ncmd + = 1    

< P> The dollar sign, by itself, "end of the line" means the following code:
  & gt; & Gt; & Gt; Import re & gt; & Gt; & Gt; Print re.compile ('$ {[a-z] *}'). Match ("$ {abcd}") None & gt; & Gt; & Gt; Print re.compile ('\ $ {[a-z] *}'). Match ("$ {abcd}") & lt; _sre.SRE_Match object 0x10 9fc51d0 & gt;   

The first is searching for the end-line at the beginning of the regexp line, so ... no. Backslash-Dollar means "No, I mean, literally matches dollar sign."

Curly braces also have special meaning, but not here.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -