A regular expression is set of pattern used to define certain amount of text. An powerful tool in any scripting language to match any pattern.
Lets have a look , how regular expression can be used in Python to solves the problem. Module “re’ is imported in python to support regular expression .
<< import re >>
[ ] – its for specifying character class, individual char or range of character can be mached .
. – Period character ,use for matching any single charcter
[code language=”python”]
In [225]: ip =’10.20.30.40′
In [226]: re.search(r”.”,ip)
Out[226]:<_sre.SRE_Match object; span=(0, 1), match=’1’_>
In [227]: re.search(r”.”,ip).group(0)
Out[227]: ‘1’