Javascript regular expression for punctuation (international)?

后端 未结 6 1282
难免孤独
难免孤独 2020-12-05 10:22

I need a regular expression to match against all punctuation marks, such as the standard [,!@#$%^&*()], but including international marks like the upside-down Spanish qu

6条回答
  •  被撕碎了的回忆
    2020-12-05 11:07

    For Python this regex to remove from the start and end any type of punctuation marks:

    import re
    def cleanspecialcharacters(str):   
        regex = re.compile((
        '^[/\"_\(\)&*\$¥\^\+=`~<>\{\}\[\]\|\-!#%\,\:;@¡§«¶·»¿;·՚-՟։֊؉،॥॰෴๏๚๛༄-༒༔༺-༽྅჻፠-፨᐀᙭᙮។-៖៘-៚‧‰-⁃⁅-⁑⁓-⁞⁽⁾₍₎、〃〈-【】〔-〟〰〽゠・﴾﴿︐-︙︰-﹒﹔-﹡﹣﹨﹪﹫!-#%-*,-/:;?@[-]_{}⦅-・〔〕《》]*|'
        '([/\"_\(\)&*\$¥\^\+=`~<>\{\}\[\]\|\-!#%\,\:;@¡§«¶·»¿;·՚-՟։֊؉،॥॰෴๏๚๛༄-༒༔༺-༽྅჻፠-፨᐀᙭᙮។-៖៘-៚‧‰-⁃⁅-⁑⁓-⁞⁽⁾₍₎、〃〈-【】〔-〟〰〽゠・﴾﴿︐-︙︰-﹒﹔-﹡﹣﹨﹪﹫!-#%-*,-/:;?@[-]_{}⦅-・〔〕《》])*$'))
        str = regex.sub('', str)
        return str
    

提交回复
热议问题