VBScript Regular Expressions to check IP address validity with some adtional characters - vbscript

How to create VB script Irregular expression syntax to check the VPparam (IP address validity) When the last octatat of the IP address is a range between ip's (x-y) and between each IP we can put the "," separator in order to add another IP
example of VBparam
VBparam=172.17.202.1-20
VBparam=172.17.202.1-10,192.9.200.1-100
VBparam=172.17.202.1-10,192.9.200.1-100,180.1.1.1-20
THX yael

I believe the term you're looking for is "regular expression", not "irregular" - might help when google searching. I don't know enough VB to provide a complete script, but the pattern you're looking for is:
(\d{1,3}\.){3}\d{1,3}(\-\d{1,3})?(,(\d{1,3}\.){3}\d{1,3}(\-\d{1,3})?)*
This will not validate that X < Y, or that each octet is in a proper range, i.e. 999.999.999.999 would be valid. You can't validate X < Y in regex (abbrev. for regular expression), so you'll need to use pattern captures to validate those yourself in the script. If you wish to validate that octets are in the proper range, replace \d{1,3} with ((1\d{2})|(2[0-4]\d)|(25[0-5])|\d{1,2}) each time it appears in the above script.

Related

Capture Filter with Wildcard in IP Address

I am trying to customize Wireshark capture such that is captures all IP addresses (both source and destination) with the IP address format xxx.xxx.xxx.100.
I used the following Capture Filter
ip matches /.*/.*/.*/.100
but the text box remains red'
These are not IP addresses in a particular range, just the fourth octet is 100
Your regex is a little off, as you need to use a backslash to escape the periods. Try this:
ip.host matches "\.100$"
That should match .100 at the end of the string.
Source: http://ask.wireshark.org/questions/22230/filter-for-partial-ip-address
Edit: Try using the Display Filter (Analyze->Display Filters..), not the Capture Filter

How to discover a date or a number near a word - only with regex within regex

I am still learning the intrinsics of regex, and am wondering if it is possible with a single regex to find a number that is at a provided distance from a word.
Consider the following text
DateClient
15-01-20130060 15-01-20140010 15-01-20150020
I want that my regex matches just 15-01-2013.
I know I can have the full DateClient 15-01-2013 with DateClient\W+\d{2}-\d{2}-\d{4}, and then apply a regex afterwards, but i'm trying to build a configurable agnostic system, that gives power to the user, and so I would like to have a single regex expression that just matches 15-01-2013.
Is this even feasible?
Any suggestions?
You can use a capturing group :
DateClient\W+(\d{2}-\d{2}-\d{4})
Example in javascript (you didn't specify a language) :
var str = "DateClient\n15-01-20130060 15-01-20140010 15-01-20150020";
var date = str.match(/DateClient\W+(\d{2}-\d{2}-\d{4})/)[1];
EDIT (following the addition of the Ruby tag) :
In Ruby you can use
(?<=DateClient\W)(\d{2}-\d{2}-\d{4})
Demonstration
Check out lookbehind for matching only the date. However, lookbehind support of your environment can be limited.
Or you could just use a capturing group, which you will be able to extract from the match result.

Need a regular expression to allow only one character in a text box in asp.net

I need a a regular expression to allow only one character for a textbox. Actually i want to validate a text filed to enter a single charecter for Initial (for name)
In a regular expression, '.' (dot) matches a single character.
If you want to be sure that this single character is alphabetic, use:
[a-zA-Z]
or in a posix system: [:alpha:]
Now, to know exactly how to implement it, we need to know in which language your code is written.
For a starter, have a look to
http://en.wikipedia.org/wiki/Regular_expression
You can set the textbox property MaxLength to 1 and use a regex to validade if a letter.

Only pull IP Address from a line of text

I've got a script that searches through a logfile for a specific trigger, and then pulls out the line when it's found. For example, this is a line I'm looking for:
7/2/10 9:24:12 AM puppetmasterd[63092] Could not resolve 10.13.1.190: no name for 10.13.1.190
It saves this line into a variable "line", but I'd like to be able to extract only the IP Address.
Our IP Addresses all start with 10.13 - is there an easy way to search for that in this variable and then isolate ONLY the IP address into a variable?
matches = line.scan(/10\.13\.[12]?[0-9]?[0-9]\.[12]?[0-9]?[0-9]/);
You want to read about regular expressions on Ruby. Your specific problem is fairly easy, so it would be a good learning exercise. (Try the tutorial if the first link is too advanced!)

Extract email addresses from a block of text

How can I create an array of email addresses contained within a block of text?
I've tried
addrs = text.scan(/ .+?#.+? /).map{|e| e[1...-1]}
but (not surprisingly) it doesn't work reliably.
Howabout this for a (slightly) better regular expression
\b[A-Z0-9._%+-]+#[A-Z0-9.-]+\.[A-Z]{2,4}\b
You can find this here:
Email Regex
Just an FYI, the problem with your email is that you allow only one type of separator before or after an email address. You would match "#" alone, if separated by spaces.

Resources