regex - Regular expression for IP Address -


i need able search through log , grab ip addresses logged. example log line like:

[2012-06-05 11:59:52] notice[14369] chan_sip.c: registration '' failed 'yy.yy.yy.yyy' - no matching peer found

i need grab ip address listed in yy.yy.yy.yyy position. other log files, yy.yy.yy.yyy in different position.

i thinking read each line, split on ' ' , loop through split temporary array for: 'yy.yy.yy.yyy'. don't know how pattern match or regex 'yy.yy.yy.yyy' single quotes included. how can this?

this regex match ip address contained in '

'(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' 

to iterate on matches in perl do:

while ($subject =~ m/'(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'/g) {     # matched text = $& } 

group 1 of match contain ip without '


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -