Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

regex in python

'''
Regex (Regular Expression) are incredibly powerful,
and can do much more than regular text search.
'''
import re 
# a. The dot Regex, how to know how to match an arbitrary character
#                   by using the dot regex.
text = '''A blockchain, originally block chain,
is a growing list of records, called blocks,
which are linked using cryptography.
'''
print(re.findall('b...k', text)) # Output: ['block', 'block', 'block']

# b. The asterisk Regex, match text that begins and ends with the character
#                       and an arbitrary number of characters. We also can use 
#                       the asterisk operator in combination
print(re.findall('cr.*', text)) # Output: ['cryptography.']
print(re.findall('y.*y', text)) # Output: ['yptography']

# c. The Zero-or-one Regex / '?' chracter, to know how to match zero
#                         or one characters.
print(re.findall('blocks?', text)) # Output: ['block', 'block', 'blocks']
Source by www.py4e.com #
 
PREVIOUS NEXT
Tagged: #regex #python
ADD COMMENT
Topic
Name
4+5 =