Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elegant regular expression to match all punctuations but not "'" in emacs Lisp?

I want to match all punctuations, but not "'", as in "I'm". For example, in the sentence below:

I'm a student, but I'm also working. 
 ^not match  ^match ^not           ^match

I can use "[[:punct:]]+" to match all punctuations, but I'm having hard time to exclude "'" from the matching pattern.

Of course, I could use someting like the following to express by enumeration, but it's much tedious, especially considering all those punctuations for Chinese as well. "[,.?!]"

Please suggest a more elegant solution.

Thanks in advance,

Yu

like image 363
Yu Shen Avatar asked Dec 11 '25 12:12

Yu Shen


1 Answers

If your regex flavor supports look-arounds, you could do this:

(?!')[[:punct:]]

In plain English: if there's no single quote when looking ahead, match any punctuation mark.

like image 70
Bart Kiers Avatar answered Dec 14 '25 05:12

Bart Kiers