How can I delete special characters?

前端 未结 5 1056
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-02 06:18

I\'m practicing with Ruby and regex to delete certain unwanted characters. For example:

input = input.gsub(/<\\/?[^>]*>/, \'\')

and fo

5条回答
  •  南方客
    南方客 (楼主)
    2021-02-02 06:40

    You can match all the characters you want, and then join them together, like this:

    original = "aøbæcå"
    stripped = original.scan(/[a-zA-Z]/).to_s
    puts stripped
    

    which outputs "abc"

提交回复
热议问题