Home > other >  About the regular expression. *? There are some questions
About the regular expression. *? There are some questions

Time:11-26

In the following, for example, one is to use. *? , another is to use. *, the output is the same, but there is some doubt, as far as I know followed? Is said not greed mode, means to match the previous sub-expression zero or one, before I understand that if use. *? , only the output to a 'genuine OpenCV' parts, but why the output will be the same here, if want to take other raw data behind the title before the first space (that is, the only access to the 'genuine OpenCV) what should be how to write a regular expression?


The import re
HTML='" raw_title ":" the original OpenCV 3 artificial neural network recognition computer vision image retrieval concept of face detection and recognition computer vision tutorial spanning the programmer "'
TLT=re. The.findall (r '\ "raw_title " : \ ". *? \ ', HTML)
"Print (TLT)

Tlt1=re. The.findall (r "" raw_title \ ": ". * \ "', HTML)
Print (tlt1)

CodePudding user response:

Greed mode: A B B, match in the end A B
Not greed mode: matching to the first B
The question is not zero or one

CodePudding user response:

You take a few more in your HTML can see the difference between the quotes,

CodePudding user response:

The regex=r (?" <=: \ "). *? (?=\ s)
"For this piece of string, can catch (the original OpenCV).
Wrong place please correct me,

CodePudding user response:

General. * is match any character, although a? A clear "break point", but then no identification character, it has been match until the end of the line,

CodePudding user response:

Respond to you. *? The difference between and. *
 import re 
HTML='" raw_title ":" the original OpenCV 3 artificial neural network recognition computer vision image retrieval concept of face detection and recognition computer vision tutorial spanning the programmer "'

TLT=re. The.findall (r '\ "raw_title " : \ ". *? Meter ', HTML)
Print (TLT)

Tlt1=re. The.findall (r '\ "raw_title " : \ ". *', HTML)
Print (tlt1)

"" "OUTPUTS:
[' "raw_title" : "the original OpenCV 3 meter ']
[' "raw_title" : "the original OpenCV 3 artificial neural network recognition computer vision image retrieval face detection and recognition meter ']" ""
  • Related