question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[beta] Regex should reuse the capture group twice

See original GitHub issue

Challenge reuse-patterns-using-capture-groups has an issue. User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0. Please describe how to reproduce this issue, and include links to screenshots if possible.



let repeatNum = "42 42 42";
let reRegex = /(\d+\s)\1/; //
let result = reRegex.test(repeatNum);

As this regex is completely new to me, I’m not exactly sure if this is a bug, but if it isn’t the lessons don’t address it.

Here’s my error: Your regex should reuse the capture group twice.

I’ve gotten all the other tests to pass and I can’t figure out how to tell what it’s doing, but if all the other tests pass then my assumption is that it is running through the capture group twice.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Manish-Giricommented, Mar 4, 2017

I’ll take this up…

0reactions
chrisdetroncommented, Sep 25, 2018

@voidbringer01 “Your reRegex tests only if it finds 3 numbers in a row. It needs to check whether a string starts with a number and ends with one, while containing 3 numbers. So in 42 42 42 42, it finds a pattern in it even thought its just an substring of it. To fix that instead of let reRegex= /(\d+)\s\1\s\1; use let reRegex=/^(\d+)\s\1\s\1$/; . ^- so that it starts with a number and $ so that it ends with a number.”

why is this the case?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Regex Question (Regular Expressions: Reuse Patterns Using ...
Your regex should reuse the capture group twice. Your regex should have two spaces separating the three numbers. Your regex should match “42...
Read more >
Capture groups using reuse patterns - Stack Overflow
Use capture groups in reRegex to match numbers that are repeated only three times in a string, each separated by a space.
Read more >
Regular Expressions - Reuse Patterns Using Capture Groups
In this regular expressions tutorial we reuse patters using capture groups. We're using regular expressions in conjunction with JavaScript ...
Read more >
4 Practical Use Cases for Regular Expressions - Bits and Pieces
The capturing group (the parenthesis and everything inside it) saves the matching part and you can reference it with “$1”. If you had...
Read more >
picocli - a mighty tiny command line interface
Picocli will instantiate this class when needed to capture command line argument values in the @Option and @Parameters -annotated fields and methods of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found