content = 'abcdd'
import re,os,sys
def test():
print content
list = re.findall(r'[.\n]+',content)
print list
if __name__ == '__main__':
test()
I know ‘.’ represent any charaters except ‘\n’
so [.\n] should represent any characters
but the result is []
why
can you help me ?
thank you in avdanvce !
.inside character class[]loses its special meaning of “all characters (except newline or not depending on flag)” and is only a plain full stop..So
[.\n]only matches full stop.or new line character.If you want to match any character (without exception), one trick is to form a character class of complementing character classes, e.g.
[\s\S]. This is useful when the regular expression of the language doesn’t support DOTALL option, which makes.matches any character.However, since Python supports DOTALL option (
re.DOTALL), so you can make use of it.Note that for Python,
.excludes only\n. For other languages, it may excludes more: Javascript.