Reputation: 9952
I've got strings like these:
+996999966966AA
-996999966966AA
I am using this code:
"+996999966966AA".gsub!(/\D/, "")
to get rid of any character except digits, but the sign + also being stripped. How can my code retain the +?
Upvotes: 6
Views: 5277
Reputation: 3693
You can also use \W
, "non-word character" which matches any character that is not a word character (alphanumeric & underscore)).
(\W\d+)\w+
Upvotes: 1