How can I delete special characters?

前端 未结 5 1062
爱一瞬间的悲伤
爱一瞬间的悲伤 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:25

    An easier way to do this inspirated by Can Berk Güder answer is:

    In order to delete special characters:

    input = input.gsub(/\W/, '')
    

    In order to keep word characters:

    input = input.scan(/\w/)
    

    At the end input is the same! Try it on : http://rubular.com/

提交回复
热议问题