Regexp Neg. set of chars HowTo?
durumdara
durumdara at gmail.com
Wed Dec 20 08:40:30 EST 2006
Hi!
I want to replace some seqs. in a html.
Let:
a-
b
= ab
but:
xxx -
b
must be unchanged, because it is not word split.
I want to search and replace with re, but I don't know how to neg. this
set ['\ \n\t'].
This time I use full set without these chars, but neg. is better and
shorter.
Ok, I can use [^\s], but I want to know, how to neg. set of chars.
sNorm1= '([^[\ \t\n]]{1})\-\<br\ \/\>\n' - this is not working.
Thanks for the help:
dd
sNorm1= '([%s]{1})\-\<br\ \/\>\n'
c = range(0, 256)
c.remove(32)
c.remove(13)
c.remove(10)
c.remove(9)
s = ["\\%s" % (hex(v).replace('00x', '')) for v in c]
sNorm1 = sNorm1 % ("".join(s))
print sNorm1
def Normalize(Text):
rx = re.compile(sNorm1)
def replacer(match):
return match.group(1)
return rx.sub(replacer, Text)
print Normalize('a -<br />\nb')
print Normalize('a-<br />\nb')
sys.exit()
More information about the Python-list
mailing list