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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:41:24+00:00 2026-05-10T18:41:24+00:00

I have a wysiwyg editor in my back end, and it is tripping up

  • 0

I have a wysiwyg editor in my back end, and it is tripping up the first regular expression I wrote. This is in PHP4, using preg_replace(). I’m capturing the URI and linked text.

@<a\shref=\'http[s]?://([^\']*)\'[]>(.*)<\/a>@siU 

The client wanted all external links to open in a new window, so that’s the expression I was using to find all (hopefully) external links, but leave internal, page anchor links, etc

I realised the wysiwyg editor also adds style='font-weight: bold' if the user selects bold on the link. I’ve only recently started learning regular expressions so I’m unsure how to go about this problem.

How would I do it?

  • 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. 2026-05-10T18:41:25+00:00Added an answer on May 10, 2026 at 6:41 pm

    this should match it alright:

    /<a\s+([^>]*)href='https?:\/\/([^']*)'(.*?)>(.*?)<\/a>/ 

    The useful thing here is the lazy match. *? it means that it’ll match only as much as it absolutely needs to, as opposed to the regular match, which is greedy.

    To demonstrate, with this text:

    a b c d a b c d

    these regexes will have different results:

    /a.*c/    selects: 'a b c d a b c' /a.*?c/   selects: 'a b c' 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data (which users input using WYSIWYG editor). I have created a
We have a client that is using a wysiwyg editor to add multiple photos
I'm using redactorjs , It's a WYSIWYG editor on jQuery. I have a textbox
I have a simple wrapper around a WYSIWYG editor (TinyMCE). I'm using JSNI to
I have created a wysiwyg editor as a standard C# program using the windows
I have been using the jhtmlarea for a wysiwyg editor. Most of it is
I have a WYsIWYG editor in my coldfusion app and need to prevent XSS
I'm trying to make a WYSIWYG editor, and so far I have it so
I have a wysiwyg editor that is changing my ampersand characters from & to
Currently I have a WYSIWYG editor for admins to post HTML pages on an

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.