4:24 PM
2
Q: how should I combine these regex?

Orion $syb =~ s/(at{3,6})/\U$1/gi; $syb =~ s/(aat{2,5})/\U$1/gi; $syb =~ s/(aaat{1,4})/\U$1/gi; $syb =~ s/(aaaat{0,3})/\U$1/gi; $syb =~ s/(aaaaat{0,2})/\U$1/gi; $syb =~ s/(a{4,7})/\U$1/gi; $syb =~ s/(aaaaaat)/\U$1/gi; $syb =~ s/(t{4,7})/\U$1/gi; Is there any way I could get all these r...

 
The plural is "regular expressions" with an S :-p "Regex" isn't a word anyway, so "regexes" or whatever you want is fine.
 
i have a string of A's C's T's and G's stored in $syb. i want to capitalize any part of the string that has a set of A's followed by T's, just A's or just T's (T's followed by A's should not) and the capitalized section may be no shorter than 4 and no longer than 7.
 
At the very end of your test string, ATT and AAAA are back-to-back separate matches. What then?
 
att is shorter than 4 and therefor should be ignored on the subject of back to back matches this would count as two AATTAAAT because it breaks at TA, however AAAATTTT would not because it is longer than 7 without breaking.
 
Oh, gotcha. Sorry, you're right, it's 3 not 4.
AAAATTTT could match AAAA followed by TTTT.
 
4:24 PM
yes which is one of the problems with the way i have it now.
how would i force it to not capitalize these instances.
 
should it match the biggest and yield AAAATTTt instead?
 
no, it needs to completely ignore anything larger than 7 correctors.
*characters
 
k
I'm playing with it now
 
thanks!
 
I'm not specifically using perl, but the regex itself should translate fine
 
4:35 PM
will a negated character class match nothing?
 
Orion, so what's the problem with just putting all these regexes in one?
 
a negated character class will match a character that isn't in that class, not "a nothing"
 
well first I'm not entirely sure how, I've tried but it would always over-matches or under-matches
 
what would?
 
well, i tried something like: /(a+t*){4,7}|(t){4,7}/
but it would match atat
 
4:43 PM
read up on lookaround assertions regular-expressions.info/lookaround.html
 
that's perfect!
 
I've been using those, and I've been so close for a while, except for matching some of those edge cases
 
this might be helpful: ideone.com/R1h44
 
lol, yeah, I guess you could just OR them all together
 
well it's better than what i had however it still doesn't solve the problem of aaaatttt
 
4:53 PM
just one char differs, altho completely different matchings
what problem?
 
well the regexp should not match aaaatttt because it is over seven characters
yours will pick up aaaa and tttt each as separate matches
so if i threw aaaattttt it would output AAAATTTT
 
(btw, the link above is no solution, just example to help understand what's going on)
why shouldn't aaaa and ttttt match separately?
you do not state anything about it
unless I missed it
 
it was in the comments
wiseguy pointed out that my current setup would match that
 
grr, I am so close...
 
but the actual reason why it shouldn't match has to do with the way dna bends
 
5:01 PM
oh, so the real problem is in your comment :p
 
yay, code golf: write a DNA sequencer in one line. lol
 
was a while ago I Perl golfed :P
 
ha ha
 
I dare say real golf can be less frustrating sometimes
 
i couldn't agree more
 
5:08 PM
last week I shot +3 on the front nine, then started the back nine with four consecutive double bogeys. No good deed goes unpunished.
 
oki, i have a solution
but i want to make a nicer one
btw, thx for a fun problem
:)
 
I'm looking forward to it.
 
in the case of "attttttt", should it become "aTTTTTTT"? (7 t's)
 
I think it should be ignored since it's a match longer than 7
according to my understanding
i.e., atttttta would match ATTTTTTa, but attttttt would not match at all
 
5:23 PM
ok, what does Orion think?
/me slaps Orion around a bit with a large trout
 
oh my bad, yes wiseguy is correct
 
oh, what kind of trout? I wanna go fishing. :-(
 
felt a bit like rainbow to me.
 
oki, nicer solution complete, altho it works as the original group of regexes, so it will turn "at{7}" to "aT{T}"
altho my less nicer solution does work for that case.
I'll post both since this one does answer your question, unless you update it :p
 
hmm lets see it
 
5:38 PM
good thing this guys answer seems wrong :p
 
I've been shooting for the "clean" one the whole time
though it's not ending up clean. lol
 
no big deal
 
at this point it's simply a personal challenge to see if I can frickin' finish it
no offense, but I'm not doing this for you anymore. :-p
I'm doing it for me.
lest I fail and have to shred my nerd card
 
haha, i understand
 
I posted an answer:
/((?<!a)a|(?<!a|t)t)((?<!t)\1|t){3,6}(?!\2|t)/
 
5:43 PM
it doesnt work
 
My test worked
 
guess used it wrong then
paste example?
 
I did it here:
Using this string: aaatcgacgatcgatcaatttcgaaaaaggattttttatgcacgcacggggattaaaaactgaaaattttactgaaaaaa‌​aa3ttttttts
and this replacement:
<\0>
because I couldn't do the uppercase replacement there.
 
yeah, does work for that
 
gonna try some tests and get back to you in a second
 
5:49 PM
i did it without capturing groups tho :p
i mean without back refs
 
seams to work perfectly for me
 
well done, Eggman
 
well, fun times guys. back to work for me. I'll log this as "General Training" :-)
 
6:04 PM
haha
 
posted mine, but too late :/
 
bah
i'd still like to see
 
it's longer because it doesnt use any back references
 
all good
one question
isn't it faster to use $1 as apposed to $&
 
only if very big strings, i've been told
 
6:13 PM
alright good to know
 
that is, only if you are matching on huge strings, since they will be duplicated if your script ever uses any of the $& $` $'
or so i've been told. i don't like this my self, and prefer to use $&
 
aaah, i am indeed matching in huge strings as in > 2000000 chars
 
6:29 PM
~2mb?
thats not too bad
or, that depends on how slow this works for you
in my solution you can easily use a capturing group, just add it around the regex and use $1 instead of $&
in the accepted one, you'll need to move the back refs a bit, but it's not really a problem
 
yeah the speed doesn't seem like its a big deal on one 2mb file however i will be running this on over ten thousand files
every second counts
 
i dont know which one is faster tho, try them both
would be interesting to know if lookarounds&alternation or back refs are faster
feels like back refs could win, but I'm no good at predicting such things. :p
 
i wonder, i have to use the regex twice in my program so i figured I'd use one of each could see which one goes faster
 
or you can use them both every time and make sure they return the same result, to make sure it's correct
;p
 
i already did that ;)
both work, and much better than my original
 
6:43 PM
and here is a less regexy solution, which is simple to understand: s/(a+t*|t+)/(length $1 >= 4 && length $1 <= 7)? "\U$1": $1/gie
but i guess would be slower
altho as I said, I'm bad at regex performance predictions ;)
 
i had something similar to that but it was indeed slower
 
Gotta go, but I hope you let us know if you get any more results from these benchmarks :p
 
allright
thanks for the help