Home > other >  Python regular expressions
Python regular expressions

Time:12-05

The import re

A='1234'
R=re. The.findall (' \ d {2} ', a)
Print (r)



Results for the '12', '34'


I want is the result of the 12 ', '23', '34'


Could you tell me how to modify your great god



CodePudding user response:

Regular should cannot be achieved

CodePudding user response:

 
The import re


Def sub (string, p, c) :
New=[]
For in the string s:
New append (s)
New [p]=c
Return '. Join (new)


If __name__=="__main__ ':
A='1234'
Results=[]
While True:
R=re search (' \ d {2} ', a)
If r:
Result=r. gutierrez roup ()
The append (result)
A=sub (a, r.s pan () [0], '*')
The else:
Break
Print (results)

CodePudding user response:

A line of regular should not line, the STR with regular digital extracted first, and then traverse into 12 ', '23', '34'
  • Related