capture essence regex mislay them, efficiently


situation:




  • text: string

  • r: regex matches biased string. competence costly calculate.



i wish both mislay r-matches text, indeed contain. currently, i like:



import re
ab_re = re.compile("[ab]")
text="abcdedfe falijbijie bbbb laifsjelifjl"
ab_re.findall(text)
# ['a', 'b', 'a', 'b', 'b', 'b', 'b', 'b', 'a']
ab_re.sub('',text)
# 'cdedfe flijijie lifsjelifjl'


this runs regex twice, circuitously i tell. there technique pass, maybe controlling re.split? seems separate formed solutions i'd need regex during slightest twice well.



Comments

Popular posts from this blog

why does floated <input> control floated component slip over too distant right ie7, nonetheless firefox?

grails record upload problems

how i emanate permitted url asp.net mvc?