carl.hiass
carl.hiass

Reputation: 1764

Stripping character at the start or end of a string

In python there is a method to replace a certain character(s) at the edges of a string, such as:

>>> "   , hello,".strip(", ")
'hello'

Is there a method to do this in javascript, or does it need to be done with a regular expression? For example:

console.log("'" + "   , hello,".replace(/^\W+|\W+$/g, "") + "'");

Upvotes: 0

Views: 43

Answers (1)

Christian Fritz
Christian Fritz

Reputation: 21354

No, there is no such method. There is only .trim(), which only trims white space.

Upvotes: 1

Related Questions