The existing scheme is:
Object according to the re module inside of a regular expression search method can specify the start and stop position features, design each found a result on a unit, and then compare all find the result of the last index the smallest is the answer of a group,
Is very troublesome, simple and direct method
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- code -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
# 2:
# to find out all of the repeating group, adopting the span () [1] the smallest group
The import re, sys
Pa=re.com running (r "(? I) ([a zA - Z]). * \ 1 ")
# using a regular expression objects can specify additional characteristics of the starting and ending position
# each find a result go forward by one unit
Start=0
Result=pa. Search (random_str, start)
Result_list=[]
# if there is no result directly print (1, 1)
If the result is None:
Print (" no repeated letters ")
Sys. Exit (0)
While the result:
Start=result. The pos + 1
# if there is repeated as a result, the continue directly
If len (result_list) & gt; 0 and the result. The span () [0]==result_list [len (result_list) - 1] [0] and result. The span () [1]==\
Result_list [len (result_list) - 1] [1] :
Result=pa. Search (random_str, start)
The continue
Result_list. Append (result)
Result=pa. Search (random_str, start)
# the last character of the plane, and find out the smallest a
Earliest_index=0
Lowest_value=https://bbs.csdn.net/topics/result_list [0]. Span () [1]
For I in range (1, len (result_list) :
If result_list [I] span () [1]
Earliest_index=I
Print (" the first English letters to repeat: ", result_list [earliest_index] group () [0])
CodePudding user response:
Need regular??For I in a:
If I in b:
Print (I)
The else:
B.a ppend (I)
CodePudding user response:
But if use regular expressions to how to write, but if the loop through is simple, the subject is to use regular expressions to...CodePudding user response:
There is no matching target and matching rules, can only be in the form of a string operation to complete the taskCodePudding user response:
Not like this?Re. The.findall (r "([a zA - Z]) \ 1", STR)
CodePudding user response:
It will appear an intermediate string not available, such as "acca", he is getting less than c of this group, it is to be able to query to a result, this in the middle of the content is passed, will ignore many thingsCodePudding user response: