- Home
- Course Detail
regularpython@gmail.com
You are now watching:
Python Regular Expressions / of Python Regular expressions special characters
dot(.) Character:
import re # . : ( dot character): Dot character is used to find any character in text except new line. data = ''' The Power of Vastu Living introduces a wonderfully accessible, room-by-room approach for organizing and decorating homes, apartments, and work spaces according to the timeless healing principles of vastu -- the sister science of yoga and ayurveda. Kathleen Coxs breakthrough system, Vastu Living, delivers all the practical tools you need to incorporate the organic, soothing properties of ancient vastu design into an increasingly overcrowded, hyper-%stressed, and e-saturated world. Now you can create a home for your soul... restore well-being to your work space... celebrate your() identity... design @your vastu blueprints... ...in every conceivable environment, from the kitchen, liv[]ing room, home office, and bedroom #to the company office, reception area -- and ev&en the dreaded cubicle. Elevate modern life through the 5,000-year-old healing properties of vastu. Enhance your inner peace, rediscover your sense of mind-and-body harmony, and always, always make room for the soul. ''' pattern = re.compile(r'\S') result = pattern.finditer(data) for l in (list(result)): print(l)
\d: It finds only digits (0-9)
# \d : It finds only digits (0-9) data = ''' The Power of Vastu Living introduces a wonderfully accessible, room-by-room approach for organizing and decorating homes, apartments, and work spaces according to the timeless healing principles of vastu -- the sister science of yoga and ayurveda. Kathleen Coxs breakthrough system, Vastu Living, delivers all the practical tools you need to incorporate the organic, soothing properties of ancient vastu design into an increasingly overcrowded, hyper-stressed, and e-saturated world. Now you can create a home for your soul... restore well-being to your work space... celebrate your identity... design your vastu blueprints... ...in every conceivable environment, from the kitchen, living room, home office, and bedroom to the company office, reception area -- and even the dreaded cubicle. Elevate modern life through the 5,000-year-old healing properties of vastu. Enhance your inner peace, rediscover your sense of mind-and-body harmony, and always, always34 make room for the soul. ''' # pattern = re.compile(r'\d') # result = pattern.finditer(data) # for l in (list(result)): # print(l) # result = re.sub(r'\D', "@", data) # print(result)
\D: This is used for finding characters except for digits
# \D : This is used for finding characters except digits data = ''' The Power of Vastu Living introduces a wonderfully accessible, room-by-room approach for organizing and decorating homes, apartments, and work spaces according to the timeless healing principles of vastu -- the sister science of yoga and ayurveda. Kathleen Coxs breakthrough system, Vastu Living, delivers all the practical tools you need to incorporate the organic, soothing properties of ancient vastu design into an increasingly overcrowded, hyper-stressed, and e-saturated world. Now you can create a home for your soul... restore well-being to your work space... celebrate your identity... design your vastu blueprints... ...in every conceivable environment, from the kitchen, living room, home office, and bedroom to the company office, reception area -- and even the dreaded cubicle. Elevate modern life through the 5,000-year-old healing properties of vastu. Enhance your inner peace, rediscover your sense of mind-and-body harmony, and always, always make room for the soul. ''' pattern = re.compile(r'\D') result = pattern.finditer(data) for l in (list(result)): print(l)
\w: This is used for finding word characters like (a-z, A-Z,0-9,_)
# \w : This is used for finding word characters like (a-z,A-Z,0-9,_) data = ''' hello world this is tutorialstution website started in 2017 @ # $ % * <gmail ''' pattern = re.compile(r'\w') result = pattern.finditer(data) for l in (list(result)): print(l)
\W: This is used for finding not a word characters. This is exactly opposite to \w
# \W : This is used for finding not a word characters. This is exactly opposite to \w data = ''' The Power of Vastu Living introduces a wonderfully accessible, room-by-room approach for organizing and decorating homes, apartments, and work spaces according to the timeless healing principles of vastu -- the sister science of yoga and ayurveda. Kathleen Coxs breakthrough system, Vastu Living, delivers all the practical tools you need to incorporate the organic, soothing properties of ancient vastu design into an increasingly overcrowded, hyper-stressed, and e-saturated world. Now you can create a home for your soul... restore well-being to your work space... celebrate your identity... design your vastu blueprints... ...in every conceivable environment, from the kitchen, living room, home office, and bedroom to the company office, reception area -- and even the dreaded cubicle. Elevate modern life through the 5,000-year-old healing properties of vastu. Enhance your inner peace, rediscover your sense of mind-and-body harmony, and always, always make room for the soul. ''' pattern = re.compile(r'\W') result = pattern.finditer(data) for l in (list(result)): print(l)
\s: This is used for finding white space, tab, and newline
# \s : This is used for finding white space, tab, and newline data = ''' The Power of Vastu Living introduces a wonderfully accessible, room-by-room approach for organizing and decorating homes, apartments, and work spaces according to the timeless healing principles of vastu -- the sister science of yoga and ayurveda. Kathleen Coxs breakthrough system, Vastu Living, delivers all the practical tools you need to incorporate the organic, soothing properties of ancient vastu design into an increasingly overcrowded, hyper-stressed, and e-saturated world. Now you can create a home for your soul... restore well-being to your work space... celebrate your identity... design your vastu blueprints... ...in every conceivable environment, from the kitchen, living room, home office, and bedroom to the company office, reception area -- and even the dreaded cubicle. Elevate modern life through the 5,000-year-old healing properties of vastu. Enhance your inner peace, rediscover your sense of mind-and-body harmony, and always, always make room for the soul. ''' pattern = re.compile(r'\S') result = pattern.finditer(data) for l in (list(result)): print(l)
\S: This is used for finding no white spaces, tabs, and newlines. It is exactly opposite to \s
# \S : This is used for finding not white spaces, tabs, and newlines. It is exactly opposite to \s data = ''' The Power of Vastu Living introduces a wonderfully accessible, room-by-room approach for organizing and decorating homes, apartments, and work spaces according to the timeless healing principles of vastu -- the sister science of yoga and ayurveda. Kathleen Coxs breakthrough system, Vastu Living, delivers all the practical tools you need to incorporate the organic, soothing properties of ancient vastu design into an increasingly overcrowded, hyper-stressed, and e-saturated world. Now you can create a home for your soul... restore well-being to your work space... celebrate your identity... design your vastu blueprints... ...in every conceivable environment, from the kitchen, living room, home office, and bedroom to the company office, reception area -- and even the dreaded cubicle. Elevate modern life through the 5,000-year-old healing properties of vastu. Enhance your inner peace, rediscover your sense of mind-and-body harmony, and always, always make room for the soul. ''' pattern = re.compile(r'\S') result = pattern.finditer(data) for l in (list(result)): print(l)
\b: Find word boundary
# \b : Find word boundary data = ''' The Power of astu Living introduces a wonderfully accessible, room-by-room approach for organizing and decorating homes, apartments, and work spaces according to the timeless healing principles of vastu -- the sister science of yoga and ayurveda. Kathleen Coxs breakthrough system, Vastu Living, delivers all the practical tools you need to incorporate the organic, soothing properties of ancient vastu design into an increasingly overcrowded, hyper-stressed, and e-saturated world. Now you can create a home for your soul... restore well-being to your work space... celebrate your identity... design your vastu blueprints... ...in every conceivable environment, from the kitchen, living room, home office, and bedroom to the company office, reception area -- and even the dreaded cubicle. Elevate modern life through the 5,000-year-old healing properties ofvastu. vastu Enhance your inner peace, rediscover your sense of mind-and-body harmony, and always, always make room for the soul. ''' pattern = re.compile(r'\bas') result = pattern.finditer(data) for l in (list(result)): print(l)
\B: not a word boundary
# \B : not a word boundary data = ''' The Power of Vastu Living introduces a wonderfully accessible, room-by-room approach for organizing and decorating homes, apartments, and work spaces according to the timeless healing principles of vastu -- the sister science of yoga and ayurveda. Kathleen Coxs breakthrough system, Vastu Living, delivers all the practical tools you need to incorporate the organic, soothing properties of ancient vastu design into an increasingly overcrowded, hyper-stressed, and e-saturated world. Now you can create a home for your soul... restore well-being to your work space... celebrate your identity... design your vastu blueprints... ...in every conceivable environment, from the kitchen, living room, home office, and bedroom to the company office, reception area -- and even the dreaded cubicle. Elevate modern life through the 5,000-year-old healing properties of vastu. Enhance your inner peace, rediscover your sense of mind-and-body harmony, and always, always make room for the soul. ''' pattern = re.compile(r'\bworl') result = pattern.finditer(data) for l in (list(result)): print(l)
^: This is used to find the beginning of a string
# ^ : This is used to find the Beginning of a string names = ["krishna", "ram","hello world", "tutorialstutions.com","krish"] pattern = re.compile(r'^kr') for name in names: print(list(pattern.finditer(name)))
$: This is used to find the end of a string
# $ : This is used to find end of a string names = ["krishna","ramesh","suresh", "ram","hello world", "tutorialstutions.com","krish"] pattern = re.compile(r'sh$') for name in names: print(list(pattern.finditer(name)))
[]: This is used to find all matched characters inside the brackets
# [] : This Is used to find all matched characters inside the brackets data = ''' The Power of Vastu Living introduces a wonderfully accessible, room-by-room approach for organizing and decorating homes, apartments, and work spaces according to the timeless healing principles of vastu -- the sister science of yoga and ayurveda. Kathleen Coxs breakthrough system, Vastu Living, delivers all the practical tools you need to incorporate the organic, soothing properties of ancient vastu design into an increasingly overcrowded, hyper-stressed, and e-saturated world. Now you can create 123 456a home for your soul... restore well-being to your work space... celebrate your identity... design your vastu blueprints... ...in every conceivable environment, from the kitchen, living room, 33 home office, and bedroom to 666 the company office, reception area -- and even the dreaded cubicle. Elevate modern life through the 5,000-year-old healing properties of vastu. Enhance your inner peace, rediscover your sense of mind-and-body harmony,9 and always, always make room for the soul. ''' pattern = re.compile(r'[09]') result = pattern.finditer(data) for l in (list(result)): print(l)
[^]: This is used to find all matched characters, not in brackets.it is exactly opposite to []
# [^] : This is used to find all matched characters not in brackets.it is exactly opposite to [] data = ''' The Power of Vastu Living introduces a wonderfully accessible, room-by-room approach for organizing and decorating homes, apartments, and work spaces according to the timeless healing principles of vastu -- the sister science of yoga and ayurveda. Kathleen Coxs breakthrough system, Vastu Living, delivers all the practical tools you need to incorporate the organic, soothing properties of ancient vastu design into an increasingly overcrowded, hyper-stressed, and e-saturated world. Now you can create a home for your soul... restore well-being to your work space... celebrate your identity... design your vastu blueprints... ...in every conceivable environment, from the kitchen, living room, home office, and bedroom to the company office, reception area -- and even the dreaded cubicle. Elevate modern life through the 5,000-year-old healing properties of vastu. Enhance your inner peace, rediscover your sense of mind-and-body harmony, and always, always make room for the soul. ''' pattern = re.compile(r'[^0-9]') result = pattern.finditer(data) for l in (list(result)): print(l)