looking for a regex that allows just parts of an ip.

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: looking for a regex that allows just parts of an ip.

Post by prometheuzz »

No problem.
s0h0
Forum Newbie
Posts: 21
Joined: Fri Feb 27, 2009 4:09 am

Re: looking for a regex that allows just parts of an ip.

Post by s0h0 »

hi,

i hope its not cheeky to ask one more time for a solution...

the needs has been changed and the mac can be entered now in 4 formats.
00:22:64:07:BB:4A
00-22-64-07-BB-4A
00226407BB4A
0022.6407.BB4A

and also for all this formats it should be possible to enter only a part of the mac...
H6-G9 for example

has anyone a RegEx that matches that needs???


thank u a lot!
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: looking for a regex that allows just parts of an ip.

Post by prometheuzz »

s0h0 wrote:hi,

i hope its not cheeky to ask one more time for a solution...

the needs has been changed and the mac can be entered now in 4 formats.
00:22:64:07:BB:4A
00-22-64-07-BB-4A
00226407BB4A
0022.6407.BB4A

and also for all this formats it should be possible to enter only a part of the mac...
H6-G9 for example

has anyone a RegEx that matches that needs???


thank u a lot!
Note that a public forum is meant to educate people about something they like to learn more about.
Without posting the things you have tried yourself, it looks* like you're just outsourcing your work here for free. I like to help people, but I find it less entertaining if people see me as an easy (and cheap!) way to do their work.
So, if you have a specific question abut some regex you wrote (but didn't work), feel free to ask it here, otherwise, I'm not interested in helping. I've already given you quite a bit of examples to work with after all.

Good luck.

* With an emphasis on the word "looks": I'm not saying you didn't try, nut by not posting your attempt, I don't know what the case is.
s0h0
Forum Newbie
Posts: 21
Joined: Fri Feb 27, 2009 4:09 am

Re: looking for a regex that allows just parts of an ip.

Post by s0h0 »

hi,

yes u are right! i just asked that cause i dont have a clou how i should get on that problem.

sorry, i wouldnt make u doing my work...
s0h0
Forum Newbie
Posts: 21
Joined: Fri Feb 27, 2009 4:09 am

Re: looking for a regex that allows just parts of an ip.

Post by s0h0 »

^([0-9a-zA-Z]{2}[:-]){0,5}[0-9a-zA-Z]{1,2}$

i got it to make the RegEx to allow just parts of the mac. but how i can hang on "or with 4 values and a dot as delimiter" i dont know...


i thought on something like this... but i know || wont work as OR assignment...

^([0-9a-zA-Z]{2}[:-]){0,5}[0-9a-zA-Z]{1,2}$ || ^([0-9a-zA-Z]{4}[.]){0,3}[0-9a-zA-Z]{1,4}$ || ^([0-9a-zA-Z]{1,12}
mintedjo
Forum Contributor
Posts: 153
Joined: Wed Nov 19, 2008 6:23 am

Re: looking for a regex that allows just parts of an ip.

Post by mintedjo »

I have no idea what you're trying to do but you can use | (single bar) for an OR in regex.
:-)
s0h0
Forum Newbie
Posts: 21
Joined: Fri Feb 27, 2009 4:09 am

Re: looking for a regex that allows just parts of an ip.

Post by s0h0 »

lol, Thank u!


^([0-9a-zA-Z]{2}[:-]){0,5}[0-9a-zA-Z]{1,2}$|^([0-9a-zA-Z]{4}[.]){0,2}[0-9a-zA-Z]{1,4}$

this one works for 3 of the 4 formats i need! im just a step away from a solution!
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: looking for a regex that allows just parts of an ip.

Post by prometheuzz »

s0h0 wrote:lol, Thank u!


^([0-9a-zA-Z]{2}[:-]){0,5}[0-9a-zA-Z]{1,2}$|^([0-9a-zA-Z]{4}[.]){0,2}[0-9a-zA-Z]{1,4}$

this one works for 3 of the 4 formats i need! im just a step away from a solution!
And it will also match these strings:

Code: Select all

00:22
00:22-00:22-0
00-0
0022.6407.B
B
0000.A
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: looking for a regex that allows just parts of an ip.

Post by prometheuzz »

s0h0 wrote:hi,

i hope its not cheeky to ask one more time for a solution...

the needs has been changed and the mac can be entered now in 4 formats.
00:22:64:07:BB:4A
00-22-64-07-BB-4A
00226407BB4A
0022.6407.BB4A

...
Hint: first create 4 different regex-es that match each of these four different cases (nothing more than that!). When you have that working, only then combine them into one regex.

Good luck.
s0h0
Forum Newbie
Posts: 21
Joined: Fri Feb 27, 2009 4:09 am

Re: looking for a regex that allows just parts of an ip.

Post by s0h0 »

thank u for ur help again.


but isnt that what i needed? it allows all 4 formats and just parts of it...?
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: looking for a regex that allows just parts of an ip.

Post by prometheuzz »

s0h0 wrote:thank u for ur help again.


but isnt that what i needed? it allows all 4 formats and just parts of it...?
That is for yourself to answer. If your regex accpets these (invalid!) addresses as well:

Code: Select all

00:22
00:22-00:22-0
00-0
0022.6407.B
B
0000.A
// etc.
then is it what you need?

I mean, you mind as well use the regex:

Code: Select all

^.*$
because that will also accept all valid addresses (and all invalid ones, of course).
s0h0
Forum Newbie
Posts: 21
Joined: Fri Feb 27, 2009 4:09 am

Re: looking for a regex that allows just parts of an ip.

Post by s0h0 »

^.*$
lol ;) good joke.


the mac should be used for a search on a database... so also parts of macs should be allowed. but they must be entered in an valid format.

which entrys would u allow if u need those 4 formats and just parts of them?



maybe that should not be allowed... 00:22-00:22-0

on server side all character like -,:,. will be removed and after every second character an minus will be inserted.
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: looking for a regex that allows just parts of an ip.

Post by prometheuzz »

s0h0 wrote:...

the mac should be used for a search on a database...
Why validate at all? Why not just query the database?
s0h0 wrote:so also parts of macs should be allowed.
Ah, a new requirement... Up until now you've only mentioned "whole" mac addresses, not parts of them. And then the question is what parts of addresses do you want to accept as valid and which ones as invalid?
Would the string "cafe" would also be valid since it's a valid hexadecimal literal? And what about "F"?
s0h0 wrote:...
which entrys would u allow if u need those 4 formats and just parts of them?

maybe that should not be allowed... 00:22-00:22-0
...
Again: that is for you to decide.
s0h0
Forum Newbie
Posts: 21
Joined: Fri Feb 27, 2009 4:09 am

Re: looking for a regex that allows just parts of an ip.

Post by s0h0 »

yes u are right again, i will resolve the specification first...
s0h0
Forum Newbie
Posts: 21
Joined: Fri Feb 27, 2009 4:09 am

Re: looking for a regex that allows just parts of an ip.

Post by s0h0 »

ok, my boss said that entries are to be allowed... so it looks like i reached the target.


thank u for this time :) i got a lil bit closer to regex and now it dont looks like hieroglyphs only :)
Last edited by s0h0 on Wed Mar 04, 2009 8:32 am, edited 1 time in total.
Post Reply