How to print regex match results in python 3? -


I was in IDLE, and decided to use regex to sort a string. But when I was told about the online tutorial, it would be printed:

  0x00000000031D7E68 object and <;  

Full program:

  import reg = re.compile ("[az] +8?") Str = "ccc8" print (reg. Match (ARR))  

Result:

  at 0x00000000031D7ED0 & lt; _sre.SRE_Match object & gt; Can anyone tell me how to actually print the results?   

You .group () to match After the function is required to be included so that it prints the match string, otherwise it will only show whether a match was played or not. To print the characters captured by the capturing groups, you can see the .group () function.

 > & gt; & Gt; Must have to pass related group index in & gt. ; Import re & gt; & Gt; & Gt; Reg = re.compile ("[a-z] +8?")) & Gt; & Gt; & Gt; Str = "ccc8" & gt; & Gt; & Gt; Print (reg.match (str) .group ()) ccc8  

With Regx capturing group.

  & gt; & Gt; & Gt; Reg = re.compile ("([a-z] +) 8?")) Gt; & Gt; & Gt; Print (reg.match (str) .group (1)) ccc  

(pattern, string, flags = 0)

If zero or more characters Returns a related matching object instance, matching the regular expression pattern at the beginning of the string. If the string does not match the pattern, then no one returns; Note that this is different from a zero-length match.

Note that even in multi-line mode, re.match () will not only match the beginning of the string and not at the beginning of each line.


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -