Hi,
Either matches give me the same result, see below :
x = " Private base address 00:1c:95:b9:e7:f0"
print("router_mac1: " + re.sub('^([0-9A-F]{2}[:]){5}([0-9A-F]{2})$','',x)) <-- Try removing $ if mac is not in the first line of the output.
router_mac1: Private base address 00:1c:95:b9:e7:f0
>>> print("router_mac1: " + re.sub('\{|master|\|0|\}|\\n','',x))
router_mac1: Private base address 00:1c:95:b9:e7:f0
For more details, you can use pythons help feature to see what fuction you can use based on their descriptions and how to match regex etc.
>>> import re
>>> help(re)
Help on module re:
NAME
re - Support for regular expressions (RE).
FILE
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py
MODULE DOCS
http://docs.python.org/library/re
DESCRIPTION
This module provides regular expression matching operations similar to
those found in Perl. It supports both 8-bit and Unicode strings; both
the pattern and the strings being processed can contain null bytes and
characters outside the US ASCII range.
Regular expressions can contain both special and ordinary characters.
Most ordinary characters, like "A", "a", or "0", are the simplest
regular expressions; they simply match themselves. You can
concatenate ordinary characters, so last matches the string 'last'.
The special characters are:
"." Matches any character except a newline.
"^" Matches the start of the string.
"$" Matches the end of the string or just before the newline at
the end of the string.
"*" Matches 0 or more (greedy) repetitions of the preceding RE.
Greedy means that it will match as many repetitions as possible.
"+" Matches 1 or more (greedy) repetitions of the preceding RE.
"?" Matches 0 or 1 (greedy) of the preceding RE.
*?,+?,?? Non-greedy versions of the previous three special characters.
{m,n} Matches from m to n repetitions of the preceding RE.
{m,n}? Non-greedy version of the above.
"\\" Either escapes special characters or signals a special sequence.
[] Indicates a set of characters.
A "^" as the first character indicates a complementing set.
"|" A|B, creates an RE that will match either A or B.
(...) Matches the RE inside the parentheses.
The contents can be retrieved or matched later in the string.
sub(pattern, repl, string, count=0, flags=0)
Return the string obtained by replacing the leftmost
non-overlapping occurrences of the pattern in string by the
replacement repl. repl can be either a string or a callable;
if a string, backslash escapes in it are processed. If it is
a callable, it's passed the match object and must return
a replacement string to be used.
THanks,
Vikas