Regex matching Python -
I want to write 3 different regular expressions first Here's what I've tried: 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. $ {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
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
& 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;
Comments
Post a Comment