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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:39:08+00:00 2026-05-12T22:39:08+00:00

I want to do THIS , just a little bit more complicated: Lets say,

  • 0

I want to do THIS, just a little bit more complicated:

Lets say, I have an HTML input:

<a href="http://www.example.com" title="Bla @test blubb">Don't break!</a>
Some Twitter Users: @codinghorror, @spolsky, @jarrod_dixon and @blam4c.
You can't reach me at blam4c@example.com.

Is there a good RegEx to replace the twitter username mentions by links to twitter, but leave @example (eMail-Adress at the bottom) AND @test (in the link title, i.e. in HTML tags)?

It probably should also try to not add links inside existing links, i.e. not break this:

<a href="http://www.example.com">Hello @someone there!</a>

My current attempt is to add “>” at the beginning of the string, then use this RegEx:

Search:  '/>([^<]*\s)\@([a-z0-9_]+)([\s,.!?])/i'
Replace: '>\1<a href="http://twitter.com/\2">@\2</a>\3'

Then remove the “>” I added in step 1.

But that won’t match anything but the “@blam4c”. I know WHY it does so, that’s not the problem.

I would like to find a solution that finds and replaces all twitter user name mentions without destroying the HTML. Maybe it might even be better to code this without RegEx?

  • 1 1 Answer
  • 1 View
  • 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-12T22:39:08+00:00Added an answer on May 12, 2026 at 10:39 pm

    First, keep the angle brackets out of your regexps.

    Use a HTML parser and xpath to select the text nodes you are interested in processing, then consider a regexp for matching only @refs in those nodes.

    I’ll let to other people to try and give a specific answer to the regex part.

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

Sidebar

Related Questions

I want to visit a page like... http://mysitelocaltion/user_name/user_id This is just a virtual link,
My HTML text is just like this: <p>abcdefghijklmnopqrstuvwxyz</p> What I want is to display
I just want to have other opinions about this one that I have been
I've got this image: I want to code this image (just the bar, not
I can't seem to find an answer on this and just want to make
This bad boy just does not want to change size to fill the dock
I just want to design this very simple website. Basically there are multiple pages
I want to port this SQL query, which works just fine on SQL Server,
I just want to know why this doesn't work (I am trying to name
I just want to ask if anybody has done something like this. Basically, it's

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.