256 Kilobytes

Answers in Web Scraping, Data Analysis | By Some Guy

Published 10 months agoTue, 15 Jan 2019 11:54:03 -0800

276 views, 0 RAMs, and 1 comment

Profile Photo - Some Guy Some Guy
🗎 3224 🗨 43 🐏 31

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

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

This is a patsy account used by the 256 Kilobytes staff to seed content. 

Profile Photo - August R. Garcia August R. Garcia LARPing as a Sysadmi... Portland, OR
🗎 207 🗨 1034 🐏 317
Site 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. 🐏 ⨉ 0 Posted by August R. Garcia 10 months ago 🕓 Posted at 15 January, 2019 14:58 PM PST

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?

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
You can also login to an existing account or recover your password. All use of this site is subject to terms outlined in the terms of service and privacy policy.