Import re# Re.match () can match the string that begins with XXX = Re.match (r "H", "Hello Python") # Print (Ret.group ()) # Group RET = Re.match (r "([^-]*) -(\d+) "," 010-12345678 ") # Print (Ret.group (1)) # By referencing the data that is matched in the grouping, but be aware of the meta string, which is similar to R" "in this format ret = Re.match (R" < ([a-za-z]* >\w*</\1> ","
Compile it once and not compile it later
Import restr = ' https://www.freebuf.com/page/357 ' pattern = Re.compile (R ' (p|s) \:\/\/www\. +?\.. +?) \/+? ', re. Dotall) match = Pattern.findall (str) print (match) print (match)
Ignore case
Add (? i) to the front of the regular expression
Import restr1 = "" "201.158.69.116--[03/jan/2013:21:17:20-0600] fwf[-] tip[-] 127.0.0.1:9000 0.007 0.007 MX PYTHONTAB.C Om get/html/test.html http/1.1 "$" 2426 "http://a.com" "es-es,es;q=0.8" "mozilla/5.0 (Windows NT 6.1) applewebkit/537.1 1 (khtml, like Gecko) chrome/23.0.1271.97 safari/537.11 "172.16.119.8-admin [15/aug/2011:18:17:50 +0800]" propfind/svn/ EAGLE http/1.1 "201 649172.16.119.8-admin [15/aug/2011:18:17:50 +0800]" Propfind/svn/eagle/!svn/vcc/default HTtP/1.1 " 207 401172.16.119.8-admin [15/aug/2011:18:17:50 +0800] "Propfind/svn/eagle/!svn/bln/31 http/1.1" 207 454172.16.119.8- admin [15/aug/2011:18:17:50 +0800] "Propfind/svn/eagle http/1.1" 207 649172.16.119.8-admin [15/aug/2011:18:17:50 +0800 ] "Propfind/svn/eagle/!svn/vcc/default http/1.1" 207 454 "" "pattern = Re.compile (R ' (? i) http/.+?\b[^\d]+? ( [2345]\d{2}) ', Re. Dotall) ret = Pattern.findall (str1) print (ret)
The dot number does not match the line break by default, and you need to set the RE to match the line break. Dotall
Pattern = Re.compile (R ' (? i) http/.+?\b[^\d]+? ( [2345]\d{2}) ', Re. Dotall)
Regular Expression Python