why result of regular expression match in not as expected?

25 Views Asked by At

Here is a javascript code

const text = 'Hello, my name is John Doe.';
const matchesIterator = text.matchAll(/(\w+) (\w+)/g);
for (const match of matchesIterator) {
  console.log(match);
}

Here is its output:

[
  'my name',
  'my',
  'name',
  index: 7,
  input: 'Hello, my name is John Doe.',
  groups: undefined
]
[
  'is John',
  'is',
  'John',
  index: 15,
  input: 'Hello, my name is John Doe.',
  groups: undefined
]

I am wondering why John Doe is not in output.

I am trying to learn javascript regular expression.i given same code to chatGPT but it is not giving me proper output.

0

There are 0 best solutions below