3.2.5.6Find all the adjectives in an English sentence
If you want to find all occurrences of a matching character in a text, you need to use the findall () function instead of the search () function . For example, if an English writer wants to find all the adjectives in an English language, he or she will use findall () to achieve this function.
Example:
Text = "He was carefully disguised but captured quickly by police."
Print (text)
Print (Re.findall (r "\w+ly", text))
The resulting output is as follows:
He was carefully disguised and captured quickly by police.
[' carefully ', ' quickly ']
In this case, it is to find out all the words with the word " ly ", and from the result it is the word with the end of Ly, which has been achieved.
3.2.5.7Find all adjectives and locations in English sentences
If you want to see not just all the adjectives that appear in the English sentence, but also the location, then using the findall () function does not reach this goal, and you need to use the finditer () function to find it, so the match Object brings back all the information, not just the string. To continue on to an example, suppose that a writer wants to find out all the adjectives used and mark out the places where he or she will do the work?
Example:
Text = "He was carefully disguised but captured quickly by police."
Print (text)
For M in Re.finditer (r "\w+ly", text):
Print ('%02d-%02d:%s '% (M.start (), M.end (), M.group (0)))
The resulting output is as follows:
He was carefully disguised and captured quickly by police.
07-16:carefully
40-47:quickly
Cai Junsheng No.: Shenzhencai Shenzhen
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
3.2.5.6 Find all the adjectives in an English sentence