Why is this RegEx not matching numbers, only characters?

I am creating a RegEx-based parser for Markdown. While working on RegEx, to find link labels in link style, I ran into an error in my RegEx that I don't see a problem with.

Given the following Markdown:

[me]: http://example.com
[her]: http://somewhere.com
[1]: http://nhs.net
[2]: http://test.com
[google it]: http://google.com

And this RegEX:

\[(\w+\s?+\w+)\]

It seems I can only detect [me], [her] and [google it], but not the tags [1] and [2]. I thought I \wshould detect both alphabetic and numeric characters?

Edit: Using the PCRE RegEx parser

+4
source share
2 answers

A template \w+\s?+\w+matches at least 2 word words due to two subpatterns \w+.

(-), ,

\[(\w+(?:\s+\w+)*)\]
      ^^^^^^^^^^^

regex

  • \[ - [
  • (\w+(?:\s+\w+)*) - 1:
    • \w+ - 1 + chars
    • (?:\s+\w+)* - :
      • \s+ - 1 ( ?, 1 0 )
      • \w+ - 1 + chars
  • ] - ] ( )

- [ ] char,

\[\b([^\][]+)\b]

\[\b a [ char, ([^\][]+) 1+, [ ] \b], ] char, . regex demo

+3

, 1+ \w+ 1 + \w+. , 2

, \s?+ . , , .

0

Source: https://habr.com/ru/post/1664571/


All Articles