user user - 2 years ago 130
Ruby Question

Rails remove phone number from text

How can I remove phone numbers from a string if they are in different formats?

For example I have:

(093) 123-34-56 (068) 123 45 67 (095) 123 456 78
Refresh Rate: 60Hz (Native). Backlight: LED (Full Array)
Smart Functionality: Yes - xx TV Streaming Platform
Dimensions (W x H x D): TV without stand (inches) : 28.98x17x3.18, TV with stand (inches) : 28.98x18.68x7.78'

How can I remove these phone numbers?

(093) 123-34-56 (068) 123 45 67 (095) 123 456 78

I have tried
, but it removes all similar numbers.

Answer Source

You can use:

text.gsub(/\([0-9]*\)\s[0-9]*(-|\s)[0-9]*(-|\s)[0-9]*/, '')

this one will remove the phones in the format you specified in your text:


and always when you are trying to write regex try to use this Rubular

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download