256 Kilobytes

Answers in Web Scraping, Data Analysis | By Some Guy

Published

479 views, 0 RAMs, and 1 comment

Profile Photo - Some GuySome GuyBasic Subscriber

How is the ?: syntax used in a regex? What does this actually do?

Download more RAM. 🐏 ⨉ 0Posted by Some Guy 2 years ago 🕓 Posted at 15 January, 2019 11:54 AM PST

This is a debug account.

Profile Photo - August R. GarciaAugust R. GarciaLARPing as a Sysadmi...Portland, ORSite Owner

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).

Source: https://stackoverflow.com/questions/18178597/non-capture-group-still-showing-in-match/1817862

More on non-capturing groups:

More on regexes:

Download more RAM. 🐏 ⨉ 0Posted by August R. Garcia 2 years ago 🕓 Posted at 15 January, 2019 14:58 PM PST

Sir, I can do you a nice SEO.

Post a New Comment

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.

Register an Account

Answers— Read More

Find more related content below!

Read More: