As you might expect, a non-capturing group is not captured in the match. For example, if you want to match phone numbers, you might require that a whitespace character be before a phone number so that you don't match, for example, the end of a username like JohnSmith1234567890 as a valid phone number. For example, here's a regex written previously to match email addresses (JavaScript):
var regex = /(?:^|\s|$)([a-zA-Z0-9.\+_-]+@[a-zA-Z0-9._-]+)/gi;
The regex wants to make sure that there is whitespace before the email, but wants to match "name@email.com" not "name@email.com" with a leading space.
Note that--when using JavaScript, at least:
The entire match will always be group 0, you need to access that specific group (group 1 in this case since the first group is non-capture).
Hire freelancers and/or advertise your goods and/or services. Hire people directly. We're not a middleman or your dad. Manage your own business transactions.
Answers in Web Scraping, Data Analysis | By Some Guy
Published
479 views, 0 RAMs, and 1 comment
How is the ?: syntax used in a regex? What does this actually do?
This is a debug account.
As you might expect, a non-capturing group is not captured in the match. For example, if you want to match phone numbers, you might require that a whitespace character be before a phone number so that you don't match, for example, the end of a username like JohnSmith1234567890 as a valid phone number. For example, here's a regex written previously to match email addresses (JavaScript):
var regex = /(?:^|\s|$)([a-zA-Z0-9.\+_-]+@[a-zA-Z0-9._-]+)/gi;
The regex wants to make sure that there is whitespace before the email, but wants to match
"name@email.com"
not"name@email.com"
with a leading space.Note that--when using JavaScript, at least:
More on non-capturing groups:
More on regexes:
Sir, I can do you a nice SEO.
Post a New Comment
To leave a comment, login to your account or create an account.
Do you like having a good time?
Register an Account
You can also login to an existing account or reset your password. All use of this site is subject to the terms of service and privacy policy.
Read Quality Articles
Read some quality articles. If you can manage to not get banned for like five minutes, you can even post your own articles.
View Articles →
Argue with People on the Internet
Use your account to explain why people are wrong on the Internet forum.
View Forum →
Vandalize the Wiki
Or don't. I'm not your dad.
View Wiki →
Ask and/or Answer Questions
If someone asks a terrible question, post a LMGTFY link.
View Answers →
Make Some Money
Hire freelancers and/or advertise your goods and/or services. Hire people directly. We're not a middleman or your dad. Manage your own business transactions.
Answers— Read More
Find more related content below!