• Nprz (unregistered)

    Wait, after 9 goes to 10, won't the next update do 20 then 30? How did it get to 26?

  • Tom (unregistered)

    I was wondering the same thing.

  • gord (unregistered)

    yeah, me too i guess the images used in the article weren't from the actual site, they made them probably without thinking to much at the numbers

  • (nodebb) in reply to Nprz

    Must have something to do with counting in hex and reverting to dec.

    Btw, that is a sh^Htrange language - not only the counterintuitive postfix if, but the result of the match() method seems to need a call to its first() method, but not the replace() method.

    Otherwise I'd expect the following sequence:

    ... -> 8 -> 9 -> 10 -> 22 -> 33 -> ...

  • Bas (unregistered) in reply to Nprz

    You're all wrong: The current value seems to be server side generated and is always right. The counter is just for these people who want to bookmark/unbookmark the current site and increases or decreases the current bookmark value with the own activity.

    The developer propably only testet this with a few bookmarks - less than 10 - an supposed a correct functionality.

  • Lurch (unregistered) in reply to Bas

    But how would the server know how many people had clicked the button?

  • Bas (unregistered) in reply to Lurch

    Maybe with some more magic - possibly some source code

  • Noughmad (unregistered)

    It's simple: the original button and count are server-generated, then when the user clicks the button, two things happen: 1) a AJAX call to the server is made, informing the server that someone has pressed the button, and 2) the count is updated locally with JavaScript. Only the second part is wrong.

  • uwe (unregistered)

    Can anybody enlighten me what the purpose of this line is? match a digit from a variable and replace with the complete variable is this the dwsperate attempt to prevent the injection of non digits? yeah client slient side with Javascript - what can possibly go wrong? but on the other hand: it was a Javascript Webdeveloper...

  • Ron Fox (google)

    When the only tool you have is a regex.....

  • Dan Bugglin (google) in reply to Nprz

    @uwe The idea is to make the count go up by 1 so the user sees their attempt at interaction was successful. Maintaining an accurate count isn't a top priority.

    I assume the developer originally had the number along with some text in the box, since they are specifically trying to pull out the number and put it back.

    If I had this code and was asked to quickly fix it ,I would change both "/\d/"s to /\d+/ in order to match against the full number. Quick and dirty but it would now function correctly with minimal changes.

    But if I was designing it from scratch, I would make a tag specifically to hold the number separate from the other content, and then I could get and put the number directly without worrying about other text content around it.

  • (nodebb) in reply to Nprz

    The counter was already 16 when the new code went live. After that, it only did the leftmost digit.

    ...and, coming right up:

    Bookmarks 10000000000000000000000000000000000000000000000000000000000000000000006

  • Jester (unregistered) in reply to Noughmad

    What language was that supposed to be? It isn't JavaScript

  • ufmace (unregistered) in reply to Jester

    Good question. Reminds me a bit of Coffeescript, but it isn't quite right, and why would there be coffeescript on the front-end anyways?

  • Nicholas "LB" Braden (github)

    I just thought that 9 other people had bookmarked it during the time the page was loaded in memory for him.

  • Carl Witthoft (google)

    INB4 : http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454

    Addendum 2016-03-24 12:12: SO, wait... how do I make a link clickable?

  • (nodebb) in reply to Carl Witthoft

    Not currently available in the New Comments System. Also: I hope it's marking this in reply to Carl Witthoft (google), because there's no visual indication it will do so.

    Addendum 2016-03-24 14:49: Edit: It did.

  • Hoodie (unregistered) in reply to Jester

    It's JavaScript, looks like they are using the Prototype.js library.

  • Dracula (unregistered)

    Some people, when faced with a problem that can't be counted by regular expressions, say "I know! I'll use context free languages!"

    Then their problem count gets a stack overflow.

  • Anomus Kovert (unregistered) in reply to Hoodie

    in reply to Hoodle:

    Can't be javascript due to these two lines ("if" and "else" are keywords):

    newCount = if (upOrDown == 'down') then (count - 1) else (count + 1)
    newCount = 0 if newCount < 1

    Maybe coffeescript? (But that wouldn't have appeared in view source of course...)

  • Clientside build (unregistered) in reply to Anomus Kovert

    With the right scripts loaded, CoffeeScript can be compiled on the fly clientside instead of precompiled on the server.

  • eric bloedow (unregistered)

    reminds me of a Flash game that quit working when i upgraded Flash to version 10-and the game thought it was version 1! so when i tried to run it, is got a "you need a newer version" message...

  • Axel (unregistered)

    Something something regex. Something something two bookmarks.

Leave a comment on “You Can't Always Count on Regular Expressions”

Log In or post as a guest

Replying to comment #:

« Return to Article