In regular expressions, it is very inconvenient to have a matching number or a letter written in English. Therefore, the regular expression introduces the connector "-" to define the range of characters, the following article mainly introduces you about how to use the regular expression in Python related data, the need for friends can refer to.
Objective
We in the previous example, we learn to use the set of characters or non-set of characters, this is to write each character, but sometimes need to put 26 lowercase letters in the collection, then by the method of the collection, you have to enter 26 times, a type to go, so more time, also prone to error, So is there a better way? This is the use of the regular expression of the connector function:-, for example, to represent 26 lowercase characters, you can use [A-z] on it.
This article gives you a detailed introduction of Python using regular expression of the connector of the relevant content, share it for everyone to reference the study, the following words do not say, come together to see the detailed introduction bar.
Examples are as follows:
#python 3.6 #蔡军生 #http://blog.csdn.net/caimouse/article/details/51749579 # from Re_test_patterns import test_patterns< C0/>test_patterns ( ' This was some text--with punctuation. ', [(' [a-z]+ ', ' sequences of lowercase '), (' [a-z]+ ', ' sequences of uppercase letters '), (' [a-za-z]+ ', ' sequences of letters of either case '), (' [a-z][a-z] + ', ' one uppercase followed by lowercase ')]
The resulting output is as follows:
' [a-z]+ ' (sequences of lowercase letters) ' This was some text--with punctuation '. ' His ' .... ' is ' ..... ' Some ' ..... ... ' with ' ..... ' ... '.. ... ' ..... ' ... '. ... ' ..... ' ... '. ... ' ... ' with '. ... '. ... '.... ' Punctuation ' [a-z]+ ' (sequences of uppercase letters) ' This was some text--with punctuation. ' ' T ' [a-za-z]+ ' (sequences of letters of either case) ' This is the some text--with punctuation. ' ' This ' ..... ' is ' .... ' Some ' ..... ... ' with ' ..... ' ... '.. ... ' ..... ' ... '. ... ' ..... ' ... '. ... ' ... ' with '. ... '. ... '.... ' Punctuation ' [a-z][a-z]+ ' (one uppercase followed by lowercase) ' This is the some text--with punctuation. ' ' This '
Summarize