« first day (287 days earlier)      last day (1165 days later) » 
03:00 - 16:0016:00 - 20:00

4:00 PM
Hm... so lookahead is called first
 
Not exactly.
 
Hun
 
If this is a function call. then the lookbehind is put on the stack first. Then the lookahead is put on the stack. Then the lookahead is evaluated. Then the lookbehind is evaluated.
 
Ok by "called" I meant evaluated.
But still, the main cursor is at the end of the line. Why lookahead?
 
So. We're stating a lookbehind. Inside that we want to make sure that what we are about to eat is an 8. Then we eat it. Since it's going on in a lookbehind, the characters that the lookbehind eats, are before the main cursor.
 
4:04 PM
So a lookahead in a lookbehind looks behind!??
 
(?<=8) is not just checking that what was just eaten by main is an 8. What happens is that the lookbehind cursor goes back one character and eats an 8. Then it returns with "I'm OK". Or "I couldn't eat an 8 here"
@Yatin No.. :D
(?<=.) this will go back one character and eat it. Anything other than a newline. It FAILS at the beginning of the string, because it can't go back.
(?<=.). will fail at every beginning character of a new line. The main cursor is not allowed to proceed.
.(?<=.) will succeed at every character.
 
Ok
But that doesn't answer my question....
 
..(?<=(?=875).) will fail on 9874. The lookahead inside a lookbehind, still looks ahead of the character that is about to be eaten :)
 
. == eats 9
.. == eats 98
 
Yes.. then what happens :)
 
4:13 PM
(?<=(?=875))
 
You missed something :D
 
.
But
 
That is the character that the lookbehind is going to eat. If it is not there, the lookbehind cursor is not going to move back.
 
Oh
 
..(?<=(?=875).) is the same as ..(?<=(?=875)8)
 
4:15 PM
what about 7 and 5?
 
It will not eat the 8 unless there's a 7 and 5 after it.
The lookbehind goes back one character, so that it can eat a .
It's now sitting between 9 and 874. Then it activated the lookahead. The lookahead now tries to eat 875.
But it can't. So the entire thing fails.
 
Ok I think I understand.
I need a break though. I am half dead here.
 
If it's 9875. Then the lookahead can eat 875. And it reports success. Then the lookbehind is happy, and proceeds to eat an 8. And reports to main "I'm happy" :)
 
So let me guess
..(?<=(?=9874)..) will give a match?
^ it does
 
Only if it's 9874 :)
 
4:19 PM
Oh god I finally understand 🙇‍♂ī¸
 
And group(0) will contain only 98 :)
 
(â”Ŧâ”Ŧīšâ”Ŧâ”Ŧ) I am brain dead now
 
It's a tricky concept really. The whole moving back and forth and several cursors is a killer.
We'll finish the joke-regex tomorrow then :)
 
Yeah. Sounds good ╰(*°â–Ŋ°*)╯
 
Heh.. wait till I give you some "Advanced Regex-Fu" :D
 
4:21 PM
T_T
 
The match only strings that have a length of 2^n is a nice teaser :)
 
It wasn't this bad
 
You can assume that they contain only one and the same character.
 
This is brain-numbing
 
It took me a while work out. It made me feel stupid.
 
4:27 PM
Np. We are all stupid until we are not ;)
 
I think it's: You can learn even if you are stupid. It's just harder and takes longer. It's nature's way of saying: Life's not fair.
And I still don't get how (?sx) . (?<=^(?:.(?<=(?=^.*?((.) \1?)$).*))*?) can be used to reverse a string.
 
Damn that looks scarry
 
No kidding :D
The first part is just flags.. (?sx) s means . can match a newline character and x means spaces are not part of the regex.
The s is useless though, because I'm only going to pay with one small line.
And it doesn't work in PCRE nor in JavaScript.
PCRE complains about "* A quantifier inside a lookbehind makes it non-fixed width"
Javascript doesn't allow for extended mode. (Ignore whitespaces)
Hmm. And I think there's also something off in JavaScript when it comes to modifying the content of a group.
Hmm. Or perhaps it's backreferences that's going weird for JavaScript.
 
 
2 hours later…
6:26 PM
I understand how it does it now. What a messy way to reverse a string.
 
:O
Tell me tomorrow ;)
 
Actually it doesn't reserve it. It just gives what to replace with what.
So for every match, replace with what is in group 2.
 
🤔
 
In Java one can use input.replaceAll(regex, "$2")
 
In python: string = string[::-1]
Without regex ;)
 
6:34 PM
lol! I think that's different, no? :)
@Yatin That does that do?
 
@Scratte Of course :p
@Scratte [] part can be told where to start, where to stop and how many steps to take...
 
@Scratte Thing about regex is that most engines cannot count. So to find the nth last character for every nth character is quite tricky.
@Yatin But.. it's empty.
 
@Scratte See this: railsware.com/blog/… ;)
 
@Yatin That's making me read it myself. I thought you were going to explain it to me :)
 
Lol Ok
So say, you have a list: nums = [10, 20, 30, 40, 50, 60, 70, 80, 90]
(lets start with lists, strings also act like lists)
Now you want to get the first element so you do:
nums[0]
 
6:41 PM
OK :) So 10 is at index 0 and 90 is at index 8 :)
 
Now, say you want to get the first 5 elements
you do:
nums[0:5]
this means go from 0 to n-1 aka 4
so you get 10 20 30 40 50
 
Ok. The end index is not included in nums[0:n]
 
Now, you can also write nums[:5]
No value == 0 if it occurs at the start
 
OK :)
 
Ok so now, say you need all elements
Then you do
nums[:]
 
6:44 PM
But.. what's the point of that? I have all the elements in nums already.
 
nums[:] means go from 0 to the end...
@Scratte I am getting there :p
 
OK :)
 
So now, say that you want the elements who are at even positions.
Then you do nums[::2]
Here 2 is the steps....
So first 0
0+2
0+2+2
And so on...
 
OK :) It's like a loop with an incrementor :)
 
So you will get: [10, 30, 50, 70, 90]
@Scratte Yep
Ok, now say you want the last element..
You do nums[-1]
this means give me the last element...
nums[-2] == 2nd last
and so on...
 
6:47 PM
Is that the same as nums[-1:0:0]? Or is the missing incrementor always 1 and a missing end always n-1?
 
@Scratte The 3nd zero doesn't make sense...
 
Ahh.. what happens with nums[-1:0:1]?
 
Take a guess ;)
 
It will just print the last element :)
 
No ;)
 
6:49 PM
It looks like the start is evaluated with a modulus.
 
 
That's odd. What if you want the last element and the first element, but the last element first?
 
Wait... you only want 2 elements?
 
Yes, well.. I'm just asking how to "slice" it so I get those two.
 
You will have to get them seperately...
nums[0], nums[-1]
 
6:53 PM
Oh.. bummer :D I think it was in reverse though, but fair enough :)
So how does nums[::-1] work?
 
So, a -ve in the step means that python starts to count from the end of the array...
So if you say [::-1] it means go from the end to the beginning
 
-ve? For positive? :)
 
Negative 😅
 
That is just confusing :)
 
Come on.. there is a - in front of the ve.... +ve == positive ;)
 
6:57 PM
positi-ve :)
I pronounce it with 3 syllables: po-si-tive :D
In Danish it's 4 syllables. Po-si-ti-ve
 
:O
 
what will nums[-1::-7] do?
 
^^ take a look at that table ;)
 
It will print the highest one first, and then the lowest one, no? :)
 
nums[high],nums[high-stride],...nums[low+1]
 
7:01 PM
Perhaps I can't count. Maybe it's suppose to be nums[-1::-8]
Wait... So all I need to do is find some online python compiler/runner, then study that page, and then I can Answer half of all the Questions coming into Stack Overflow? :D
 
Lol kinda :p
 
How do you get a count of the elements in your nums?
 
len(nums)
 
So nums[-1::-len(nums)] do work?
 
[a:b:c]

len = length of string, tuple or list

c -- default is +1. The sign of c indicates forward or backward, absolute value of c indicates steps. Default is forward with step size 1. Positive means forward, negative means backward.

a -- When c is positive or blank, default is 0. When c is negative, default is -1.

b -- When c is positive or blank, default is len. When c is negative, default is -(len+1).
So specifying -1 for a isn't needed.
 
7:08 PM
Oh.. nice :)
 
nums[::-9]
 
But that will only work if you know how long it is, It nums is the size of 100, then -9 is a bit short :)
 
So here you want to go from -1 to -10
@Scratte I am just giving an example :p
 
And my nitpicking says that you can't specify the size of the entire array :)
Oh. I'm still on: I want the last element, then the first element :D
I get like that. If I can't find a way to go something, I'll keep going at it until I work it out.
 
so first it gets -1 then -1+9 = 8 which doesn't exist so it stops....
so all you get is [90]
So you want to go from -1 to 0
 
7:12 PM
I was thinking of nums[::-8] which I suspect would give me the last element, and then count down to the first element, and give me that.
 
Nah that will become infinite then 😅
 
Hmm.. I need to find an online python tool :)
 
@Scratte How about we get the first and then the last and then reverse the resulting array
Although tbh you are better off doing [nums[-1],nums[0]]
simplest way ;)
 
@Yatin Don't know how to work that :)
I guess I was expecting some >>>
 
7:22 PM
I figured out the other one though :)
nums = [10, 20, 30, 40, 50, 60, 70, 80, 90]
print(nums)
print(len(nums))
print(nums[::-8])
print(nums[::-len(nums)+1])
it prints:
[10, 20, 30, 40, 50, 60, 70, 80, 90]
9
[90, 10]
[90, 10]
>
That is the last element and the first element :)
 
Oh nice :)
 
Hehe.. I'm working your array :P
 
Anyways. I have gtg ;)
 
Thanks for the lecture :)
 
Thank you too ;)
 
7:27 PM
@Yatin "Python. Indexing and Slicing for Lists, Tuples, Strings, and other Sequential Types"
Oh.. your "Python" site can run Java 10 :O
 
03:00 - 16:0016:00 - 20:00

« first day (287 days earlier)      last day (1165 days later) »