Regex to match only letters

后端 未结 20 1827
孤城傲影
孤城傲影 2020-11-22 16:24

How can I write a regex that matches only letters?

20条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 16:42

    JavaScript

    If you want to return matched letters:

    ('Example 123').match(/[A-Z]/gi) // Result: ["E", "x", "a", "m", "p", "l", "e"]

    If you want to replace matched letters with stars ('*') for example:

    ('Example 123').replace(/[A-Z]/gi, '*') //Result: "****** 123"*

提交回复
热议问题