Strip characters from header in Ruby -


i http x-forwarded-for header:

15.207.26.45[chr(0)]'"`, 10.3.94.196, 178.210.90.90, 172.31.49.107 

i parsing ip addresses, , remove characters have no place in comma-delimited list of ipv4 or ipv6 ip addresses.

i tried various regexes gsub, without success. appreciated.

in example string of ipv4 addresses, following should return ipv4 addresses , skip else.

([0-9]{1,3}\.){3}[0-9]{1,3} 

...oh, , match both ipv4 , ipv6:

([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-f]{1,4}\:){7}[0-9a-f]{1,4} 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -