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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:47:25+00:00 2026-05-27T11:47:25+00:00

Regex-noob here. Looking for some C# regex code to syntax highlight twitter text. So

  • 0

Regex-noob here. Looking for some C# regex code to “syntax highlight” twitter text. So given this tweet:

@taglius here's some tweet text that shouldn't be highlighted #tagtestpix http://aurl.jpg

I want to find the user mentions (@), hashtags (#), and urls (http://) and add appropriate html to color highlight these elements. Something like

<font color=red>@taglius</font> here's some tweet text that shouldn't be highlighted   <font  color=blue>#tagtestpix</font> <font color=yellow>http://aurl.jpg</font>

This isn’t the exact html I will use, but I think you get the idea.

  • 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-27T11:47:25+00:00Added an answer on May 27, 2026 at 11:47 am

    The following would match the ‘@’ character followed by a sequence of alpha-num characters:

    @\w+
    

    The following would match the ‘#’ character followed by a sequence of alpha-num characters:

    \#\w+
    

    There are a lot of free-form http url match expressions, this is the one I use most commonly:

    https?://[-\w]+(\.\w[-\w]*)+(:\d+)?(/[^.!,?;""\'<>()\[\]\{\}\s\x7F-\xFF]*([.!,?]+[^.!,?;""\'<>\(\)\[\]\{\}\s\x7F-\xFF]+)*)?
    

    Lastly, You’re going to get false positive hits with all of these so you’re going to need to look real hard at how to correctly delineate these tags… For instance you have the following tweet:

    the url http://Roger@example.com/#bookmark is interesting.
    

    Obviously this is going to be a problem as all three of the expressions will match inside the url. To avoid this you will need to figure out what characters are allowed to precede or follow the match. As an example, the following requires a whitespace or start of string to precede the @name reference and requires a ‘,’ or space following it.

    (?<=[^\s])@\w+(?=[,\s])
    

    Regex patterns are not easy, I recommend getting a tool like Expresso.

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

Sidebar

Related Questions

Here's a basic regex technique that I've never managed to remember. Let's say I'm
Okay, I am a noob to regex, and I am using this site for
I'm still a Scala noob, and this confuses me: import java.util.regex._ object NumberMatcher {
This one is killing me,i'm a total noob with regex. Im trying to make
Regex really does nothing if i run this code: input contains: geeeeekdldn Regex.Replace(input, @g(.|\n)*?n,
I am new to regex expressions so sorry if this is a really noob
I have some text that I want to match and replace in C# The
Regex newbie here. There's a (broken) plugin for the forum software I use that
Another noob regex problem/question. I'm probably doing something silly so I thought I'd exploit
Yep - another noob regex query, which I can't seem to get. I'm trying

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.