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

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -