Advertisement
Guest User

Untitled

a guest
Oct 27th, 2017
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. import re
  2.  
  3. userString = input('Please enter a string to strip: ')
  4. charStrip = input('Please enter any characters you\'d like to omit: ')
  5.  
  6. def stringStrip(userString, charStrip):
  7.     if charStrip == '':
  8.         noWhite = re.compile(r'[^\s][\w]+[^\s]')
  9.         mo1 = noWhite.search(userString)
  10.         print(mo1.group())
  11.     else:
  12.         noChar = re.compile(r'[' + charStrip + ']')
  13.         mo2 = noChar.sub('', userString)
  14.         print(mo2)
  15.        
  16. stringStrip(userString, charStrip)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement