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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:41:31+00:00 2026-05-30T14:41:31+00:00

I need a C# Regex pattern to find telephone numbers in a string and

  • 0

I need a C# Regex pattern to find telephone numbers in a string and reformat them.

The telephone numbers could be in any format, eg 00 0000 0000 or (00) 0000 0000 or +00 0 0000 0000 or 0000 0000 or 00-0000-0000 or similar formats. So I am basically looking for at least 8 characters of 0-9, plus, minus, space or brackets, up to 20 characters max. This string will only contain phone number(s) and a bit of text so there will be no problem with any other numbers.

I want to replace the numbers found with a hyperlink to that telephone number like the example below with the non-numbers stripped out of the A tag.

<a href="tel:0000000000">00 0000 0000</a>

This is the code I came up with myself which almost works:

string regex = @"(\b[0-9+\(][\(\)0-9 +-]{6,20}[0-9]\b)";
Regex r = new Regex(regex, RegexOptions.IgnoreCase);
litTelephone.Text = r.Replace(faculty.Telephone, "<a href=\"tel:$1\">$1</a>");

It works with many numbers except it doesn’t pick up this example +00 0 0000 0000 if it is at the start of the string (it drops off the leading plus). It also doesn’t remove the non-numbers from the A tag.

I don’t know why I am so crap at regular expressions!

  • 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-30T14:41:32+00:00Added an answer on May 30, 2026 at 2:41 pm

    In your regex, keeping exclusively a match if it is following a ”greater than” (>) will allow you to exclude the number that you want to change:

    (?<=>)[\+]?(\b[0-9+\(][\(\)0-9 +-]{6,20}[0-9]\b)

    Something similar to this would also handles extension:

    (?<=>)([\+0-9]{1,3}([ \.\-])?)?([\(]{1}[0-9]{3}[\)])?([0-9A-Z \.\-]{1,32})((x|ext|extension)?[0-9]{1,4}?)

    Sorry to excessively edit my answer.

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

Sidebar

Related Questions

What regex pattern would need I to pass to java.lang.String.split() to split a String
I am using the matches string builtin and need to run a regex pattern
I need a regex for the following pattern: Total of 5 characters (alpha and
I`m parsing SQL query with C# Regex. I need also to make my pattern
I need a Regex Statement (run in c#) that will take a string containing
I need help writing a regex for a phone number pattern that allows the
I need to find all the regex matches from a list of strings. For
I'm using Sybase 12.5.3, and want/need to do regex pattern matching. The Sybase help
i need to find few words or matching pattern using a Javascript. this is
I need to rename approximately 50,000 files and can't find regex examples that work.

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.