0

This isn't so much about how to achieve what is explained in the example, there are plenty of easy ways to do it. The question is WHY does the example not behave as expected?

1. If I have the following string

"#foo#bar"

2. And I'm trying to get [foo, bar] with the following regex in JavaScript

"#foo#bar".match(/(?:#)([a-zA-Z]*)/gi)

3. It returns

Array [ "#foo", "#bar" ]

Ignoring the non-capturing group (?:#)

It works as I first expected in here https://regex101.com/r/zI0wH9/1

So why is this? Do JS regexes behave somehow differently?

nardeas
  • 633
  • 6
  • 14

1 Answers1

-1

simply try

"#foo#bar".match(/[a-zA-Z]+/gi); //outputs ["foo", "bar"]
gurvinder372
  • 66,980
  • 10
  • 72
  • 94
  • Yes but WHY doesn't the above work / behaves differently in JS vs. regex101 ? – nardeas May 24 '16 at 12:24
  • 1
    It does not differ from regex101. You get the same matches, but the `MATCH INFORMATION` pane **only shows captured group values from ID1 to ID*n***. Blame regex101 for confusing terminology. – Wiktor Stribiżew May 24 '16 at 12:36