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

  • Home
  • SEARCH
  • 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 8762623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:34:36+00:00 2026-06-13T15:34:36+00:00

I am having a problem with regular expressions at the moment. What I’m trying

  • 0

I am having a problem with regular expressions at the moment.
What I’m trying to do is that for each line through the iteration, it checks for this type of pattern: Lastname, Firstname
If it finds the name, then it will take the first letter of the first name, and the first six letters of the lastname and form it as an email.

I have the following:

$checklast = "[A-z],";
$checkfirst = "[A-z]";
if (ereg($checklast, $parts[1])||ereg($checkfirst, $parts[2])){ 
    $first = preg_replace($checkfirst, $checkfirst{1,1}, $parts[2]);
    print "<a href='mailto:$first.$last@email.com;'> $parts[$i] </a>"; 
}

This one obviously broke the code. But I was initially attempting to find only the first letter of the firstname and then after that the first six letters of the lastname followed by the @email.com This didn’t work out too well. I’m not sure what to do at this point.

Any help is much appreciated.

  • 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-06-13T15:34:37+00:00Added an answer on June 13, 2026 at 3:34 pm

    How about something like this:

    $name = 'Smith, John';
    $email = preg_replace('/([a-z]{1,6})[a-z]*?,[\\s]([a-z])[a-z]*/i', 
                          '\\2.\\1@email.com', $name);
    
    echo $email; // J.Smith@email.com
    

    Cheers

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

Sidebar

Related Questions

I'm having problems with regular expressions that I got from regexlib. I am trying
I'm new to Regular Expressions and am having difficulty getting patterns that I find
i am having a problem creating a regular expression that will validate if the
I am having a problem with a non-greedy regular expression (regex). I've seen that
I'm trying to build a regular expression that matches regular expressions between two forward
I'm having a problem when trying to apply a regular expression to some strings
I'm trying to work my way through some regular expressions; I'm using python. My
i am having a problem with dealing with regular expressions. What i need is
I'm having this issue with a regular expression in PHP that I can't seem
I’m having a problem with Regular Expressions in C#. What I have is a

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.