0

In this much upvoted question 12 years ago, it has been asked, how to extract the content of brackets e.g.

I want to find an answer on the internet [stackoverflow].

The wanted expression to extract the brackets and the content is

\[.*?\]                     # -> [stackoverflow]

while the

(?<=\[)(.*?)(?=\])    # -> stackoverflow

extracts the content only. I would like to match only those expression that are not longer than 10 characters.

My guess would something like

\[.*?\]{,100}

but that is not working. Where do I put the condition of the maximal length?

Uwe.Schneider
  • 1,112
  • 1
  • 15
  • 28
  • 2
    Do you mean 10 with `[` and `]`? `\[[^][]{0,8}]`? Or `\[[^][]{0,10}]` (12 with `[` and `]`)? – Wiktor Stribiżew Sep 25 '21 at 20:42
  • In the post, `100` would be the maximum length, with 0 being the minimum. This is clearly no `10`. Defining “not working” with relevant details is usually a productive start. (Python might require an explicit number before the comma in the **“interval quantifier”**; the syntax varies a bit.) Anyway, https://blog.finxter.com/python-regex-greedy-vs-non-greedy-quantifiers/ might be a handy read. – user2864740 Sep 25 '21 at 20:43
  • By "not working" I meant not matching in [online regex testing](https://regexr.com/) – Uwe.Schneider Sep 25 '21 at 20:51
  • 1
    more like `\[.{,10}\]` – diggusbickus Sep 25 '21 at 20:54
  • Unfortunately, e.g. ```\[[^][]{0,1000}]``` or ```\[[^][]{0,10}]``` is not matching. – Uwe.Schneider Sep 25 '21 at 20:56

0 Answers0