Skip to content
DevMeme
2380 of 7590
Bugs Post #2646 · source on Telegram

The Regex Quantifier Betrayal

Description

A very tight dark-theme code screenshot shows syntax-highlighted Python-like regex code, including a visible fragment resembling `re.findall('index":"(\d*)_(\d*)"', ...)` and a following line converting captured groups with `int(lGroup[0][0])` and another `int(...)` call. The key visible pattern uses `\d*`, which means zero or more digits, rather than `\d+`, which would require at least one digit. The sibling caption says, "The Look your regex gives you when you use asterisks instead of plus," framing the crop as a classic regular-expression footgun. The technical humor is that one quantifier character can silently admit empty captures and push the failure downstream into parsing or type conversion.

Comments

18
Anonymous ★ Top Pick The gap between `\d*` and `\d+` is exactly one character wide and somehow still large enough to fit an outage.
  1. Anonymous ★ Top Pick

    The gap between `\d*` and `\d+` is exactly one character wide and somehow still large enough to fit an outage.

  2. Deleted Account 5y

    parsing json with regex why

    1. Deleted Account 5y

      Лан

    2. @cozgerest 5y

      Лан

    3. @goistheworstlanguageever 5y

      Лан

    4. @LionElJonson 5y

      Лан

    5. @gas2600 5y

      coz can и лан

    6. @foreshape 5y

      Лан

    7. @akionka 5y

      Лан

    8. Deleted Account 5y

      Лан

    9. Deleted Account 5y

      Лан

    10. @nenten 5y

      Лан

    11. Deleted Account 5y

      Лан

  3. Deleted Account 5y

    validating is not parsing

  4. Deleted Account 5y

    regex in the pic won't match "index":\n"245_445" which is a totally valid json

    1. @ogroleg 5y

      👍

  5. @willowfragment 5y

    "asterisks"... "plus"... why not call them what they are, which is "zero or more occurrences " and "one or more occurrences "

  6. @s2504s 5y

    B/c this is easy?

Use J and K for navigation