Wednesday, 12 August 2015

Day 1 - text formation

formating text

enter = '\n' #will give enter
tabulator = '\t'

space = '\b'

(a|b|c) matches exactly one of a, b or c.
any digit = '\d'
only one digit = '\d{1}'
only two digits = '\d{2}'       # example 34 or 45 or 78
more then one digit = '\d+'   # example 5 or 23 or 234 or 4234923094
zero or more digit = '\d*'   # example 5 or 23 or 234 or 4234923094 or none
optional any digit = '\d?'

anything EXCEPT digit = '\D'
it can be also '\D{} or '\D+' or '\D*'  or '\D?'

^ - that is crazy sign. It tells Python to look at string from the very beggining. Look below:
phonePattern = re.compile(r'(\d{3})\D*(\d{3})\D*(\d{4})\D*(\d*)$')
and
phonePattern = re.compile(r'^\D*(\d{3})\D*(\d{3})\D*(\d{4})\D*(\d*)$')

the yelow expresion will start compile when the first requirement is fulfilled so it will start in '800 ....'

the grey expresion will compile from the very beggining of phonePattern so it will check also ''work 1-(800) 555.1212 #1234')"


No comments:

Post a Comment