^Hehe so true
Ryan M
Not sure if you'll see this, but your regular expression for Session ID's got me thinking. And yes sometimes that dangerous for me when it comes to regex. I often end up with something working. Only to look back it 5 min later and think what on earth was I doing, or what even is that. That's if things go well, there is also the chance I get lost in a logic nightmare that feels inescapable.
Anyway this is inspired from your work, so I thought I'd share. I also have an alterer motive, in that if it's flawed, you'll pick up on it
This whole premise is basic, find a string in a sting. I thought surely this shouldn't need many code branches, permutations or computations.
Anyway here's what I came up with and it's quite similar to yours.
sId = document.URL.match(/c=.+?(?=\/)/);
A condition of a capture group's condition is where my regex dies fast, but this time I think I got a handle on it
The difference is this is a bit stricter. For example
forum/c=/forums.w
will return null, where as the other one accepts it and returns "c=/". Not really a big issue, however one thing I know is people land on the forums via external links. I just want to cover as much as possible. I still may work on it and improve on it some more, but for now I feel a big improvement on my existing methods.
Edit: It doesn't have to return null.
Example:
sId = document.URL.match(/c=.+?(?=\/)/) || "Damn it, Log in!"
Result can have trailing forward slash, by use of [] match rather than () capture.
sId = document.URL.match(/c=.+?
[
?=\/
]
/);
Hope you like