() Mark the beginning and end position of a sub-expressions .
Import Re A = ' { "name": "# WX #", "Sex": "# F #"} ' C = " (.? *) # # " # match preceding expression 0 or 1 y = the re.search (C, A) Print (y.group ()) Print (y.group (. 1 )) ------------------------- - operating results # WX # WX
. Matches any character (except newline)
Import Re A = " # # kk12222foo " B = " . " # matches any character S = the re.search (B, A) Print (s.group (0)) ------------- --------------- operating results #
^ Matches the beginning of the string
Import Re A = " # # kk12222foo " B = " ^ # " # matches the beginning of the string S = the re.search (B, A) Print (s.group (0)) ---------- ----------------- operating results #
$ The end of the match the string
Import Re A = " # # kk12222foo " B = " # $ " # end of the matched string S = the re.search (B, A) Print (s.group (0)) ---------- ---------------- operating results #
* Match 0 or more times in front of the sub-expression appears
Import Re A = " # # kk12222foo " B = " . * " # matches the previous expression 0 or more times this S = the re.search (B, A) Print (s.group (0)) ----- ----------------------- operating results # kk12222foo #
+ Match 1 or more times in front of the sub-expression appears
Import Re A = " # # kk12222foo " B = " 2+ " # foregoing match expression 1 or more S = the re.search (B, A) Print (s.group (0)) ----- ------------------- operating results 2222
? Matches the preceding subexpression zero or one
Import Re A = " 44444, # # kk12222foo " C = " . 4? " # Match preceding expression 0 or 1 Y = the re.search (C, A) Print (y.group (0)) --- ---------------------------- operating results
4