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 8872741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:17:41+00:00 2026-06-14T18:17:41+00:00

Using a single regex line (this goes in a config file for an application)

  • 0

Using a single regex line (this goes in a config file for an application) I need to capture the localpart of an email address.

If it consists of only numbers, pass it along unmodified.
If it has any non-numeric character on it, truncate to 11 chars max.

I made this simple program to test but if the localpart is over 11 characters there is no match (the whole email address is printed).

#!/usr/bin/env perl

my @emails = ('the-chuck.t1.norrisson@chuck.com', '358451399991@chucksphon.com', 'ph33t@gmail.com', 'the-average.guyisbald@example.com', 'alongnameit@11chars.com', 'alongnameitis@13chars.com', 'a1234567890@11charnum.com');

for my $email (@emails){

    # will put $1$2 on the substituion spot
    $email =~ s/^(\d+)@.+|^([a-zA-Z0-9._%+-]{1,11})@.+/  /;

    print '===> ' . $email  . " \n\n ";

}

Where am I going wrong?

  • 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-14T18:17:42+00:00Added an answer on June 14, 2026 at 6:17 pm

    You need to include a regex atom such as \S*? in case the number of characters exceeds 11…

        $email =~ s/^(\d+)@.+|^([a-zA-Z0-9._%+-]{1,11})\S*?@.+/$1$2/;
    

    Using this produces correct output:

    [mpenning@Bucksnort ~]$ perl sample.pl
    ===> the-chuck.t
    
     ===> 358451399991
    
     ===> ph33t
    
     ===> the-average
    
     ===> alongnameit
    
     ===> alongnameit
    
     ===> a1234567890
    
     [mpenning@Bucksnort ~]$
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to retrieve the date from the line below using a single regEX.
I'm using the single page application template in MVC 4. The template created the
This is a page using a single jQuery.ajax posting to the same page and
I want to parse the following statement using regex: (o) Multi line text (o)
I have a data file in which each line represents a single record and
Given the URL (single line): http://test.example.com/dir/subdir/file.html How can I extract the following parts using
I am using Single Table Inheritance for managing different types of projects. Models: class
why php escapes backslashes when using single quotes? I'm trying to output \\ on
How can i insert multiple values in a sql table using single statement. Doing
I am in a computer arch class and we are doing mips using single

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.