473,699 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

regexp problem

Hi
If I want to validate certain IP Address range
say in an IP Address range of : "15.70.186. 15-100",
here where 15.70.186 is the network id and 15-100 is
the host id. I want to discover all IP Addresses that
fall in between 15.86.70.15 - 15.70.186.100 .
what regexp do i need to use ?

regds
kbs
Jul 19 '05 #1
2 2709
> If I want to validate certain IP Address range
say in an IP Address range of : "15.70.186. 15-100",
here where 15.70.186 is the network id and 15-100 is
the host id. I want to discover all IP Addresses that
fall in between 15.86.70.15 - 15.70.186.100 .
what regexp do i need to use ?


Do you really need to use regular expression? If in future you will
change IP range you should rewrite regex. Regexes are not too sutaible
to deal with range checking (it is possible but the expression is not
human-friendly).

I think the best is to write a two-line function such as

sub check_ip_range{
my @ip = $_[0] =~ /^15\.70\.186\.( \d+)$/;
return ($ip[3] >= 15 && $ip[3] <= 100);
}

Jul 19 '05 #2
If I want to validate certain IP Address range
say in an IP Address range of : "15.70.186. 15-100",
here where 15.70.186 is the network id and 15-100 is
the host id. I want to discover all IP Addresses that
fall in between 15.86.70.15 - 15.70.186.100 .
what regexp do i need to use ?


Do you really need to use regular expression? If in future you will
change IP range you should rewrite regex. Regexes are not too sutaible
to deal with range checking (it is possible but the expression is not
human-friendly).

I think the best is to write a two-line function such as
sub check_ip_range{
my ($ip) = $_[0] =~ /^15\.70\.186\.( \d+)$/;
return ($ip >= 15 && $ip <= 100) ? "+" : "-";
}

print check_ip_range ("15.70.186.90" );

Jul 19 '05 #3

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

Similar topics

19
2179
by: Magnus Lie Hetland | last post by:
I'm working on a project (Atox) where I need to match quite a few regular expressions (several hundred) in reasonably large text files. I've found that this can easily get rather slow. (There are many things that slow Atox down -- it hasn't been designed for speed, and any optimizations will entail quite a bit of refactoring.) I've tried to speed this up by using the same trick as SPARK, putting all the regexps into a single or-group in...
0
1386
by: Ed Leafe | last post by:
I recently upgraded to 4.1 alpha (MySQL 4.1.0-alpha-standard-log) on my Linux server, and came across a problem with a query that had been working in 3.23 that no longer worked in 4.1a. I've simplified the query to demonstrate the problem: select trim(upper('foo')) regexp ('^foo$') as trimUpper, upper('foo') regexp ('^foo$') as justUpper, trim('foo') regexp ('^foo$') as justTrim, trim(upper('foo')) as trimUpperFoo, upper('foo') as...
10
7685
by: Andrew DeFaria | last post by:
I was reading my O'Reilly JavaScript The Definitive Guide when I came across RegExp and thought I could tighten up my JavaScript code that checks for a valid email address. Why does the following not appear to work: var email_address = "Joe@Schmoe"; var email_regex = new RegExp ("^(\\w+)(\@)(\\w+)(\.)(\\w+)$"); var result = email_regex.exec (email_address); alert (" result = \"" + result + "\"\n" + " result = \"" + result + "\"\n" + "...
6
56817
by: Mark Findlay | last post by:
I am trying to figure out how to set up my reg exp search so that the search will only match on the exact word. Here is the current problem code: Word1 = "RealPlayer.exe" Word2 = "Player.exe" RegExp re = Word2; if (re.Find(Word1))
1
1224
by: geos | last post by:
hello, I have the problem writing the regular expression to verify the valid system path in the way that RegExp.$1 has to contain path up to the parent folder of a file, and RegExp.$2 should contain a file name (or be empty if there was no file in the path). The allowed characters are all except \ / : * ? " < > | The problem I have is to find a smart way to separate the file part from the rest of the path.. could you give me some hints...
6
1414
by: Christoph | last post by:
I'm trying to set up client side validation for a textarea form element to ensure that the data entered does not exceed 200 characters. I'm using the following code but it doesn't seem to be working correctly: if( this.value != '' ) { if( !( RegExp( '^{0,200}$' ).test( this.value ))) { alert( 'Information provided must not be more than 200 characters.' ); this.focus(); } }
7
3448
by: Csaba Gabor | last post by:
I need to come up with a function function regExpPos (text, re, parenNum) { ... } that will return the position within text of RegExp.$parenNum if there is a match, and -1 otherwise. For example: var re = /some(thing|or other)?.*(n(est)(?:ed)?.*(parens) )/ var text = "There were some nesting parens in the test"; alert (regExpPos (text, re, 3));
9
1936
by: vbfoobar | last post by:
Hello I am looking for python code that takes as input a list of strings (most similar, but not necessarily, and rather short: say not longer than 50 chars) and that computes and outputs the python regular expression that matches these string values (not necessarily strictly, perhaps the code is able to determine patterns, i.e. families of strings...).
2
14670
by: Uldis Bojars | last post by:
Hi All, I have encountered problems with JS RegExp.exec() and can't find what is the problem. Could you help me? formRequest is a function that extracts some information from XMLHTTPRequest response. A very strange effect (and I can't find where I've done something wrong) is that regexp matches in this function fail on every second call.
4
2535
by: r | last post by:
Hello, It seems delimiters can cause trouble sometimes. Look at this : <script type="text/javascript"> function isDigit(s) { var DECIMAL = '\\.'; var exp = '/(^?0(' + DECIMAL
0
8628
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9054
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8943
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7785
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5884
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3075
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2362
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2016
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.