Regex

共 2 篇文章。

Bug in Python re implementation?

Development

Python includes a Regular Expression implementation, called re. However, I thought that I have hit a bug.

The following regular expression is apparantly wrong, but Python spend much CPU time to give a mismatch:

_mailcheck = re.compile("^(\w|.){3,25}$")
_mailcheck.match(“foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo”)

I think the “.” would override anything (including “\w”), but this does not happen…

参与评论

Useful sed(1) regular expressions

Cheatsheets

Source code cleanup:

sed -i '' -E s/\ \	/\	/g *.c *.h
sed -i '' -E s/^\ \ \ \ \ \ \ \ /\	/g *.c *.h
sed -i '' -E s/\	\ \ \ \ \ \ \ \ /\	\	/g *.c *.h
sed -i '' -E s/\ +\$//g *.c *.h
阅读全文… ( 本文约 76 字,阅读大致需要 1 分钟 )