Regex replace all commas with value

前端 未结 4 1797
长发绾君心
长发绾君心 2021-02-13 12:36

I have a string that looks like this: \"Doe, John, A\" (lastname, firstname, middle initial).

I\'m trying to write a regular expression that converts the string into \"D

4条回答
  •  面向向阳花
    2021-02-13 13:16

    Try this out to remove all spaces and commas, then replace with *.

    Myname= myname.replace(/[,\s]/,"*")

    Editted as removing 'at least two items' from the pattern. But to have at least on item.

    Myname= myname.replace(/([,\s]{1,})/,"*")

    Reference: on Rublar. However you are better off with regexpal as per m.buettner :)

提交回复
热议问题