How to check string contains special character in ruby

前端 未结 7 1698
我在风中等你
我在风中等你 2021-02-12 22:31

How to check whether a string contains special character in ruby. If I get regular expression also it is fine.

Please let me know

7条回答
  •  情话喂你
    2021-02-12 23:18

    "Hel@lo".index( /[^[:alnum:]]/ )
    

    This will return nil in case you do not have any special character and hence eaiest way I think.

提交回复
热议问题