re.compile string.punctuation

string_punctuationBest way to strip punctuation from a string in Python
http://stackoverflow.com/questions/12437667/how-to-replace-punctuation-in-a-string-python

>import string
>import re
>
>regex = re.compile(‘[%s]’ % re.escape(string.punctuation))
>
>out = regex.sub(‘ ‘, “This is, fortunately. A Test! string”)
>
>’This is  fortunately  A Test  string’

Advertisements

Python Regular Expressions

newpythonlogoThe Python Standard Library > 6. Text Processing Services > re
https://docs.python.org/3.4/library/re.html

Regular expressions HOWTO:
https://docs.python.org/3.4/howto/regex.html
For … science underlying regular expressions (deterministic and non-deterministic finite automata), you can refer to almost any textbook on writing compilers.

Metacharacters are not active inside classes: … '$' is usually a metacharacter, but inside a character class it’s stripped of its special nature.

Perhaps the most important metacharacter is the backslash, \.

Some of the special sequences beginning with '\' represent predefined sets of characters

* doesn’t match the literal character *; instead, it specifies that the previous character can be matched zero or more times, instead of exactly once.

Pay careful attention to the difference between * and +;

match() versus search()

========================================

Regular expressions
http://www.pythonlearn.com/html-008/cfbook012.html

Python Regular Expressions
2012
https://developers.google.com/edu/python/regular-expressions

Christopher Potts emoticons
https://class.coursera.org/nlp/lecture/145

Python: Regular expressions
University of Cambridge
http://www.ucs.cam.ac.uk/docs/course-notes/unix-courses/archived/archived-python-courses/PythonRE/files/PythonRE.pdf

regular123