Get the App
SLTechnology News&Howtos  ›  Development  › 

How to remove all English punctuation except preserving punctuation set by JavaScript

Shulou Source: shulou.com Published: 2022-06-01 02:56:19 09月19日 Update

This article will explain in detail how JavaScript can remove all English punctuation except the punctuation set. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Clear all English punctuation marks (including spaces) except for keeping the punctuation set.

All English punctuation marks are: ~ `! @ # $% ^ & * ()-_ + = [] {};: "', /?

The parameter excludePunctuation refers to the set of punctuation marks that need to be preserved. For example, if the value passed is'_', it means that all English punctuation marks except _ are cleared.

Function clearPunctuation (str,excludePunctuation=null) {

Let regexp = new RegExp (`[${getExcludePunctuation (excludePunctuation)}]`,'g')

Return str.replace (regexp,'')

What language is javascript? javascript is a dynamically typed, weakly typed language, based on object and event driven, relatively secure and widely used in client-side web page development. It is also a widely used scripting language for client-side Web development. It is mainly used to add dynamic functions to HTML web pages, and now JavaScript can also be used in web servers, such as Node.js.

This is the end of this article on "how to remove all English punctuation except the punctuation set by JavaScript". I hope the above content can be of some help to you so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Punctuation punctuation symbols English language articles dynamic client client more type web page script development good practical security event content function Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Docker macOS MariaDB Apple