Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> import re
- >>> regex = re.compile(r'^( )*([^ ])*( )*$')
- >>> regex.search(' asdfgh ').group(2)
- 'h'
- p = re.compile("^(s+)((.+)(?=S).)(s+)$")
- print p.search(" some textt of several words n").group(2)
- p = re.compile("^(s+)((.+)(?=S).)(s+)$", re.DOTALL)
- p.search(" somentext ").group(2) --> "somentext"
- r1 = re.compile("^s+")
- r2 = re.compile("s+$")
- s = re.sub(p1, '', re.sub(p2, '', "tsomenttextn"))
- s == "somenttext" # True
- def strip(s):
- strip.r1 = re.compile("^s+")
- strip.r2 = re.compile("s+$")
- return re.sub(strip.r1, '', re.sub(strip.r2, '', s))
- strip("tsomentext t") # -> "somentext"
- def strip(s, symbols=r"s"):
- strip.r1 = re.compile("^[{}]+".format(symbols))
- strip.r2 = re.compile("[{}]+$".format(symbols))
- return re.sub(strip.r1, '', re.sub(strip.r2, '', s))
- strip("tsomentext t") # -> "somentext"
- regex = re.compile(r'^(s*)([^ ]*)(s*)$')
- regex = re.compile(r'^( *)([^ ]*)( *)$')
- import re
- def reStrip( text, delim=" " ):
- return re.sub( '^['+re.escape(delim)+']*|['+re.escape(delim)+']*$', "", text )
- reStrip( " sdf ", " s" ) // 'df'
- >>> import re
- >>> [re.fullmatch(r's*(.*?)s*', s, re.S).group(1) for s in ['', ' ', ' anbt']]
- ['', '', 'anb']
- r'S+'
- import re
- result = re.search(r'S+', ' asdfgh ggggggg oooo')
- print result.group(0)
- asdfgh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement