Python uses the re module to verify dangerous characters

The re module is a unique module for matching strings in Python. Many functions provided in this module are implemented based on regular expressions, and regular expressions are used to perform fuzzy matching on strings and extract the string parts they need. All languages are common. note:

Use the re module to define a pattern string for verifying dangerous characters, verify two paragraphs of text, and output the verification result:

import re
pattern = r'(hacker)|(Capture)|(monitor)|(Trojan)'
about ='I am a programmer, I like to read books about hackers, and I want to study Trojan'
match =re.search(pattern,about)if match == None:print(about,'@Safety!')else:print(about,'@Dangerous words appeared!')
about ='I am a programmer, I like to read computer books and develop websites'
match =re.search(pattern,about)if match == None:print(about,'@Safety!')else:print(about,'@Dangerous words appeared!')

result:

I am a programmer, I like to read books about hackers, and I want to study Trojan @ There are dangerous words!
I am a programmer, I like to read computer books, and I like to develop websites @安全!

The above is the whole content of this article, I hope it will be helpful to everyone's study.

Recommended Posts

Python uses the re module to verify dangerous characters
Python uses the email module to send mail
How to view the python module
How to learn the Python time module
How to install the downloaded module in python
How to save the python program
Python uses pdfkit to generate pdf [python]
How to verify successful installation of python
Python string to judge the password strength
How does Python handle the json module
Python novice learns to use the library
Python uses pandas to process Excel data
Python3 module
How to use the round function in python
How to use the zip function in Python
An article to understand the yield in Python
How to use the format function in python
Detailed explanation of the usage of Python decimal module
How to enter python through the command line
Python uses PIL to cut and stitch pictures
Python how to move the code collectively right
The best way to judge the type in Python
Use python to realize the aircraft war game