Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4589012
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:00:17+00:00 2026-05-21T22:00:17+00:00

I am new to the world of coding as well as PHP and am

  • 0

I am new to the world of coding as well as PHP and am having a hard time understanding how regular expressions are read.

For example, I constructed the simple regular expression below that is a weak attempt to validate an email address.

The email address – test@test.com

The regular expression – ^([0-9a-zA-Z])+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$

What I would like to understand is how each segment of the email address in this example is dealt with and read e.g.

  1. test would be considered as segment 1,
  2. @ would be considered the second segment,
  3. the periond(.) would be considered the third segment,
  4. etc

Obviously if I introduce an additional segment to the equation e.g. test-123 the regular expression fails.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T22:00:18+00:00Added an answer on May 21, 2026 at 10:00 pm

    the basics are

    ^([0-9a-zA-Z])+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$
    

    ^ matches start of string
    () matches a segment which you can extract and use, if you were using preg_match for example

    ([0-9a-zA-Z])+ means it will match 1 or more of those characters specifed only
    for an email address there are other chars that are valid, you should read the email RFC if you want to get into that detail
    https://www.rfc-editor.org/rfc/rfc5322

    there are alternative ways of doing this, eg if you used the /i modifier at the end of your pattern you can make it case insensitive, and then you don’t need to specify both a-z and A-Z

    /^([0-9a-z])+@([-0-9a-z]+[.])+[a-z]{2,6}$/i
    

    the @ symbol is pretty obvious, a necessary part of the email address (in external systems, internal email doesn’t always need an @ as it can default to the internal domain)

    ([-0-9a-zA-Z]+[.])+
    this part matches the main part of the domain, I notice you have included hyphen – in the charset this time. also I am thinking you should have \. rather then just . by itself, as . matches anything, not fullstop as you would expect.

    so it would match 1 or more of these characters [-0-9a-zA-Z], followed by any character at all

    [a-zA-Z]{2,6}
    matches [a-zA-Z] with minimum length of 2, and max length 6

    $ matches then end of the string
    if you had spaces after end of the email address it would fail validation, so you would need to trim it first in that case

    matching an email address is actually not an easy thing to start with as there are quite a number of variations that are all valid

    for example these could all be valid email addresses
    bumperbox
    bumperbox@invalid.com
    bumper-box@invalid.com
    bumperbox@invalid.co.uk
    bumper.box@subdomain.invalid.school.nz

    Your best bet is to use one of the already established email validation patterns available around the web, there are a few discussions about email validation in the php manual under preg_match, etc

    you can also use functions such as filter_var if you have a recent (5.2+) version of php
    http://nz.php.net/manual/en/function.filter-var.php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to the world of coding as well as CSS. Having read
I am new to the world of coding as well as PHP and befuddled
I am new to the world of coding as well as PHP and am
I am new to the world of coding as well as php and am
I am new to the world of coding, XHTML, CSS as well as PHP.
I am new to the world of coding, PHP and object oriented programming. I
I am new to the world of coding as well as XHTML. I am
I am new to the world of coding as well as CSS. I have
I am new to the world of coding, XHTML, CSS and PHP. This is
I'm new to JScript coming from a C++ world. I'm quite surprised that expressions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.