lists in Python • The twenty-minute trouble ticket system • Tim Bray: "No New XML Languages" • How to use vim, really • You really should learn regular expressions • Quick, but not dirty, PHP Hi, great regex! It only does not match lower case also the windows output of ipconfig/all (using a dash as delimiter) is not covered here's my addition: /^([0-9a-f A-F][:-])[0-9a-f A-F]$/i Thanks for the update, Bjoern.
The "/i" modifier at the end already makes it case-insensitive (assuming you're using Perl-compatible regexes), but adding the dash as a separator is a good improvement.
I am writing a program to read in data from an excel sheet which contains a bunch of info about computers which will be entered by the user.
The second one is not valid in most flavors, except for BRE/ERE, which supports character range collation.
However, support for character range collation varies among implementation, so the result may vary.
I needed an easy way to validate a MAC address in a bash script that generated a unique hostname based on the MAC address of the system.
This gem did the trick: [code lang="bash"] echo ":3e:a" | egrep "^([0-9a-f A-F]:)[0-9a-f A-F]$" [/code] In the event that there was a problem getting the MAC address (e.g., faulty NIC or unstable device driver), I generate a random hostname instead of basing the hostname generation on the MAC.
I can read all the values no problem but I just need help validating MAC and IP addresses entered by the user to make sure the information is correct.
Some regular expressions for this would be great as I am sure I would use them again at some stage.
Try this chunk of code out: ) __END__ My MAC address is 00-00-00-00-00-00 over there, and it's : over here, and the date/time happens to be 2001-05-25-. The thought of that honestly had not crossed my mind. It's not very often that I run across spots to backref in a match or the LHS of a substitution. -marius 1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right.
When he states that something is impossible, he is very probably wrong. Hi marius, The thread "One for the regexp fans" from last fall also deals with parsing MAC addresses, albeit from a little different angle.
There are three common tasks related to storing mac address in the database as char(12) (it is feasible to use bigint instead but in our case we opted for a text type).
In our case user is allowed to enter mac address the way s/he wants: 000CF15698AD 00:0C: F: AD 00-0C-F1-56-98-AD So the perfect solution would be to apply regular expression like this one: /([a-f A-F0-9][:|\-]?
Now I'm building the core platform of a global startup accelerator. (If you're using this in a double-quoted PHP string, escape the "$" with a backslash.) Some related posts: What happens when you screw up?