last day (14 days later) » 

5:02 AM
1
A: Regex pattern search for alternating character case

mikeservset aAbBaBbA bAbBaA bbAb AAaBbAa BBBaaa aBaB l= u=; printf %s\\n "$@" | grep -E "^([${l:=[:lower:]}][${u:=[:upper:]}])+$|^([$u][$l])+$" OUTPUT: aAbBaBbA bAbBaA aBaB

 
was hoping to do this without a script :) otherwise I would have checked with python.. but I think I could use the regex you have in there
 
@NoTime - You can do it without a script - the for loop is just to get it all over to grep but actually, that's not the best way to do it....
 
I changed it to full command, I still don't fully understand why range from A-Z wouldn't work
 
@NoTime - it might, but that is a locale specific range - A-Z and a-z depend on the C locale's sort order by ASCII byte value - if you start working with locales in which that is not true, [[:lower:]] and [[:upper:]] are the robust classes - so you might as well just do it robustly from the start.
 
I honestly started with those from the start, but was unable to get past repeating characters without having to redirect the output into a file, then append with a different regex.
 
5:02 AM
@NoTime - I think it might go back to the pattern vs reference confusion... There might be something in this that could help clear that up.
@NoTime - actually, now that I think about it, even this fails for odd numbers of characters. I'll fix that...
 
the logic you gave me works as a command
even with odd. the script might not though
 
It does?
I thought it would need a [u|l]? at the end of each...
 
the change to my answer .. here let me copy pasta
ls |grep -E '([[:upper:]][[:lower:]]+$|^[[:lower:]][[:upper:]])+$'
 
No - that breaks. Try with aBaBa.
 
the script though.. i think it runs different
it works
idk maybe my stuff is different
 
5:07 AM
You're missing a ( in the second one is why - in which case it should also match things you don't want it to.
 
dang..
 
Oh, and the ) on the left side - those groups need to be explicit.
 
yeah its getting multiple again
 
You need to match any number of pairs of characters - either u - l or l - u.
 
today is my first day working with regex, so I am not sure if that is a part of it?
the u -| if that is abbreviation for upper
 
5:09 AM
So that excludes odd numbers of chars - which is why you need ^([u][l])+[u]?$|^([l][u])+[l]?$
Yeah.
So one or more pairs of upper then lower or lower then upper followed by 0 or 1 odd chars.
You see?
 
I understand why you are doing that yes
I am not getting it to work, so I need to figure where i made mistake
 
That's the only way to get only the alternates. Try it like this:
 
ok got it was missing a colon
ls |grep -E '^([[:upper:]][[:lower:]]+[[:upper:]]?$)|^([[:lower:]][[:upper:]])+[[:lower:]]?$‌​'
 
Nope/
You need the pairs grouped.
 
rr.. where
 
5:13 AM
^(12)+1?$|^(21)+2?$
 
ok i missed first groups got 2nd though it looks like
ls |grep -E '^([[:upper:]][[:lower:]])+[[:upper:]]?$)|^([[:lower:]][[:upper:]])+[[:lower:]]?‌​$'
jeez this is annoying
 
You've got one too many )
 
ls |grep -E '^([[:upper:]][[:lower:]])+[[:upper:]]?$|^([[:lower:]][[:upper:]])+[[:lower:]]?$‌​'
 
Yup.
 
do you program as well?
 
5:15 AM
That will get em all.
I dabble. This all came of a hobby - but I just really liked to learn. I've got pretty good at the shell/admin stuff. And some C, but I've done nothing worthwhile. I don't know how to start.
 
have you messed with learn python the hard way? or learn C the hard way?

I had a python class, but you are already there if you can understand this
python is pretty easy to get started
 
Yes, I did python in college - it did my math homework. I'm not a fan though - it feels ... cheap or something. Maybe I'm just a snob.
 
you can do some calls to other things if you really want.. I mean you could make a python program to run C if you really wanted :)
it has objects for object oriented though
python does..
 
Yeah - that is cool about it. You can do the same in your shell, though. cc - -o proggie
 
it seems easier in python, but that doesn't make it better :) it's just a simple language, but it is used on a lot of stuff
C is supposed to be more powerful for sure
You have helped me on a lot of questions. Especially with ESP and UEFI. Learned a lot from you. Thanks.
 
5:23 AM
whats the grep for anyway?
 
I had an extra credit question, on just a regular assignment (like less than %1 of grade) But it was annoying me that I couldn't figure it out
I already turned it in, but I'd rather know the answer
 
Those are the fun ones,
 
Thanks for the help. I gotta get to bed
see ya later
 

last day (14 days later) »