I am using regular expressions to look for certain keyword sin a string. At the moment I have got:

import re
thisText = "<meta http-equiv='content-type' content='text/html; cHarSet=gBk' />"

n = re.compile(r'\b\s*charset=gbk[a-z]*', re.IGNORECASE|re.VERBOSE)
print n.findall(thisText)

this allows me to get the string, ignoring the case of the text. I also want it to ignore whitespace i.e if the text i am searching is charset = gbk I want it to match charset=gbk. Is there anyway of doing this?

Something like this maybe.

import re

html = '''\
"<meta http-equiv='content-type' content='text/html; cHarSet=gBk' />"
'''

test_match = re.search(r'cHarSet\=(\w*)', html)
print test_match.group()
#-->cHarSet=gBk
print test_match.group(1)
#-->gBk
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.