preamble
We have learned the function of enumerating collections, listing all the characters that need to appear, and saving them in the collection, so that the regular expression can judge whether the match is successful according to whether the characters in the collection exist or not, if they are in the collection, the match will be successful, otherwise it will not be successful. Now there is a problem, that is, the collection of characters listed in the collection can not appear to match the success of this demand how to realize it? In fact, it is relatively simple, you just need to add a character ^ in front of the set, so that when the regular expression matches, it finds that there is a character in the set will not match successfully. The following words do not say much, to see the details of the introduction.
Examples are as follows:
#python 3.6 #Cai Junsheng #/caimouse/article/details/51749579 # from re_test_patterns import test_patterns test_patterns( 'This is some text -- with punctuation.', [('[^-. ]+', 'sequences without -, ., or space')], )
The resultant output is as follows:
'[^-. ]+' (sequences without -, ., or space) 'This is some text -- with punctuation.' 'This' .....'is' ........'some' .............'text' .....................'with' ..........................'punctuation'
In this example, just exclude the underscore, period, and spaces (-, . , , ) and other characters are excluded.
summarize
Above is the entire content of this article, I hope that the content of this article on your learning or work has a certain reference learning value, if there are questions you can leave a message to exchange, thank you for my support.