473,405 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Find IP with a RegExp

Hi people,

How can I find a IP adress in a string using regexp?

Received: from unknown (HELO u7b3u5) (na****@200.228.69.237 with login)
Thanks to all.
Nov 14 '05 #1
12 4662
vi******@sordido.com.br (Vinicius) wrote in
news:6c**************************@posting.google.c om:
How can I find a IP adress in a string using regexp?

Received: from unknown (HELO u7b3u5) (na****@200.228.69.237 with login)


I'll answer this if you can tell me what this has to do with the C
language.

--
- Mark ->
--
Nov 14 '05 #2
begin followup to Mark A. Odell:
I'll answer this if you can tell me what this has to do with
the C language.


Apart from time travel C is not very useful. Use perl instead.

$ perl -ne 'm/\d+\.\d+\.\d+\.\d+/ && print $&' < data
200.228.69.237

--
Für Google, Tux und GPL!
Nov 14 '05 #3
Alexander Bartolich wrote:
begin followup to Mark A. Odell:
I'll answer this if you can tell me what this has to do with
the C language.


Apart from time travel C is not very useful. Use perl instead.

$ perl -ne 'm/\d+\.\d+\.\d+\.\d+/ && print $&' < data
200.228.69.237


Why do people keep posting broken perl "solutions" to comp.lang.c?

$ perl -ne 'm/\d+\.\d+\.\d+\.\d+/ && print $&' <<< 12345.12345.12345.12345
12345.12345.12345.12345

"Some people, when confronted with a problem, think ``I know, I'll
use regular expressions.'' Now they have two problems." - JWZ

Jeremy.
Nov 14 '05 #4
Alexander Bartolich wrote:
begin followup to Mark A. Odell:
I'll answer this if you can tell me what this has to do with
the C language.

Apart from time travel C is not very useful. Use perl instead.

$ perl -ne 'm/\d+\.\d+\.\d+\.\d+/ && print $&' < data
200.228.69.237


Not useful? Funny that you'll still need C to compile the PERL
processor, see perl.c in the PERL distribution :)

Seth

~ Let us linux ~
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Nov 14 '05 #5
begin followup to Jeremy Yallop:
Why do people keep posting broken perl "solutions" to comp.lang.c?
Because it's fun.

perl -ne 'm/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/ && print $&' < data
"Some people, when confronted with a problem, think ``I know, I'll
use regular expressions.'' Now they have two problems." - JWZ


--
# The Slam Dunk Answer
# They can go with me, or they can go with you, or they can go nowhere.
# But gee, the last two options are the same.
-- Larry Wall in <19*******************@netlabs.com>
Nov 14 '05 #6
Alexander Bartolich wrote:
begin followup to Jeremy Yallop:
Why do people keep posting broken perl "solutions" to comp.lang.c?


Because it's fun.

perl -ne 'm/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/ && print $&' < data


Still broken. It wrongly accepts "333.444.555.666" (and doesn't
recognize "_127.0.0.1_", which perhaps it should).

Jeremy.
Nov 14 '05 #7
begin followup to Jeremy Yallop:
Still broken. It wrongly accepts "333.444.555.666"
Well, inet_aton has to be good for something. And whether the
overhead of a regular expression is better than than a brute
force loop with strstr ... is really just another kind of dick
sizw war.
(and doesn't recognize "_127.0.0.1_", which perhaps it should).


By the same logic you can say it should also recognize IPv6.
But then who knows what the OP really wants.

--
Für Google, Tux und GPL!
Nov 14 '05 #8
Alexander Bartolich wrote:
begin followup to Jeremy Yallop:
Still broken. It wrongly accepts "333.444.555.666"


Well, inet_aton has to be good for something. And whether the
overhead of a regular expression is better than than a brute
force loop with strstr ... is really just another kind of dick
sizw war.


Correctness, not overhead, is the primary issue. All the code in this
thread that uses regular expressions has been hopelessly broken. This
isn't the right place to debug Perl code, though, as pointed out
already.

Jeremy.

Nov 14 '05 #9
Alexander Bartolich <al*****************@gmx.at> writes:
begin followup to Jeremy Yallop:
Why do people keep posting broken perl "solutions" to comp.lang.c?


Because it's fun.

perl -ne 'm/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/ && print $&' < data


Not really. The above solution recognizes many things that look like
IP addresses, but are invalid. It may also fail to recognize some
things that are valid IP addresses. I won't go into the details,
because this (a) isn't the right place for it, and (b) I'm not sure of
the exact definition of a valid IP address (or, rather, of the textual
representation of a valid IP address).

The use of Perl is obviously off-topic, but a complete response would
require discussion of the RFC or RFCs that define the format, and
would probably veer off into IPV6 issues as well. If I tried to
discuss it here, I would miss the opportunity to have my inevitable
mistakes corrected by experts.

C has no built-in support for regular expressions, though of course
numerous regular expression packages have been written in C.

If you want to present a definition of a valid IP address and ask how
to recognize strings that match the definition in portable C, this is
the place to discuss it -- ideally by posting a short working code
sample and asking why it doesn't work. Otherwise, there are more
appropriate newsgroups.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 14 '05 #10
begin followup to Jeremy Yallop:
Correctness, not overhead, is the primary issue.
This is a meaningless sequence of buzzwords.
Correctness primarily requires a correct definition of correctness.
All the code in this thread that uses regular expressions has
been hopelessly broken.


No other code has been posted. Ok, this may be because the whole
issue is way off-topic. Aggravated by severe immunity against
trolling amongst regulars.

Anyway, the funny thing about your definition of 'hopeless' is
how little change is required after each redefinition of the task
at hand.

#!/usr/bin/perl -wn
BEGIN { use Socket; }
m/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/ && inet_aton($&) && print $&;

--
The Paternal Patter Answer
# That's okay, <name>, I understand where you're coming from.
# I once went through the rebellious stage you're going through,
# but eventually I settled down and started getting some real work
# done. These things just take time. Be patient with yourself.
-- Larry Wall <19*******************@netlabs.com>
Nov 14 '05 #11
vi******@sordido.com.br (Vinicius) wrote:
# Hi people,
#
# How can I find a IP adress in a string using regexp?
#
# Received: from unknown (HELO u7b3u5) (na****@200.228.69.237 with login)

tclsh <<':eof'
set d {([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])}
set p {[.]}
set string {Received: from unknown (HELO u7b3u5) (na****@200.228.69.237 with login)}
if {[regexp $d$p$d$p$d$p$d $string ip]} {
puts $ip
}
:eof

--
Derk Gwen http://derkgwen.250free.com/html/index.html
Title does not dictate behaviour.
Nov 14 '05 #12
Alexander Bartolich wrote:
Anyway, the funny thing about your definition of 'hopeless' is
how little change is required after each redefinition of the task
at hand.
There has been no such redefinition.
#!/usr/bin/perl -wn

[snip]

Sorry, but it's still both broken and off-topic.

Jeremy.
Nov 14 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: hokiegal99 | last post by:
How do I say: x = string.find(files, 'this', 'that', 'the-other') currently I have to write it like this to make it work: x = string.find(files, 'this') y = string.find(files, 'that') z =...
3
by: trialofmiles | last post by:
Is there any reason why RegExp wouldn't be able to find a period? str = '256.89'; a = new RegExp('(\.)'); b = /(\.)/; alert(str.replace(a, 'x$1x')); alert(str.replace(b, 'x$1x')); The alert...
11
by: Laiverd.COM | last post by:
Hi, In the following function I keep getting a 'Object expected at line 75 char 5' but for the life of me I cannot find the error. Maybe someone would be so kin to have a look? I indicated the...
5
by: Illya Havsiyevych | last post by:
Hello Anybody knows regexp used in CodeModule Find Method I'm trying to use regexp's to find all procedures in CodeModule Maybe there is other way in Access Thank You Illya
4
by: Jon Maz | last post by:
Hi All, I want to strip the accents off characters in a string so that, for example, the (Spanish) word "práctico" comes out as "practico" - but ignoring case, so that "PRÁCTICO" comes out as...
8
by: Dmitry Korolyov | last post by:
ASP.NET app using c# and framework version 1.1.4322.573 on a IIS 6.0 web server. A single-line asp:textbox control and regexp validator attached to it. ^\d+$ expression does match an empty...
26
by: Matt Kruse | last post by:
Are there any current browsers that have Javascript support, but not RegExp support? For example, cell phone browsers, blackberrys, or other "minimal" browsers? I know that someone using Netscape...
1
by: Karen | last post by:
I am very new to MySQL- I currently have an VBA module using a VBSCript that will find different aspects of a text string that are a unique text string and turn it into a not so unique text string....
8
by: poolboi | last post by:
hey guys, i got a question on REGEXP in SQL if i have a row containing the info NAME : 12344455667678 how can i use a SELECt with REGEXP
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.