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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:40:31+00:00 2026-06-06T14:40:31+00:00

I have regex patterns in PHP $s = preg_replace(#\[URL\=(.*)\](.*)\[\/URL\]#Ui, <a href=\$1\ target=\_blank\>$2</a>, $s); $s

  • 0

I have regex patterns in PHP

$s = preg_replace("#\[URL\=(.*)\](.*)\[\/URL\]#Ui", "<a href=\"$1\" target=\"_blank\">$2</a>", $s);
$s = preg_replace("#\[CODE\=(.*)\](.*)\[\/CODE\]#Uis", "<pre class=\"brush: $1\">$2</pre>", $s);
$s = preg_replace("#\[URL\](.*)\[\/URL\]#Ui", "<a href=\"$1\" target=\"_blank\">$1</a>", $s);
$s = preg_replace("#\[IMG\](.*)\[\/IMG\]#Ui", "<p align='center'><img src=\"$1\" border=\"0\" /></p>", $s);

How could I convert those to JavaScript?

I tried for this combination but it’s not working (?)

body.replace(/\[URL\=(.*)\](.*)\[\/URL\]/g, '<a href=\"$1\" target=\"_blank\">$2</a>');

@Kolink
This is working for single image

body = body.replace(/\[IMG\]([\d\D]*)\[\/IMG\]/gi, '<p align="center"><img src="$1" border="0" /></p>');

but if I add second image it all crashes becauase in this example

[IMG]http://www.someimage.com/123.jpg[/IMG]Test
[IMG]http://www.someimage.com/456.jpg[/IMG]

match will be

http://www.someimage.com/123.jpg[/IMG]Test[IMG]http://www.someimage.com/456.jpg
  • 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-06T14:40:32+00:00Added an answer on June 6, 2026 at 2:40 pm

    You need to add i after the g to make the regex case-insensitive.

    Additionally, JavaScript doesn’t support a “multiline” modifier. Instead, you will need to replace . with something like [\d\D].

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

Sidebar

Related Questions

Sigh, regex trouble again. I have following in $text : [img]http://www.site.com/logo.jpg[/img] and [url]http://www.site.com[/url] I
I have tried several regex patterns (designed for use with PHP because I couldn't
Possible Duplicate: A PHP regex to extract php functions from code files I have
How can i pass multiple patterns to the regex.replace() pattern parameter? In PHP you
I have the following Regex (in PHP) that I am using. '/^[a-zA-Z0-9&\'\s]+$/' It currently
I have some JavaScript, which is generated by PHP code, using a template. The
I have this regex in PHP: preg_match('/\[summary\](.+)\[\/summary\]/i', $data['text'], $match); It works fine when the
I have the following string: $/Mycollection/Branches/Dev/New/php/MySite/src/MySite/somefolder/src/sad.php I need to create regex pattern and take
I have stumbled upon a really odd bug with PHP's preg_replace function and some
Usually when my regex patterns look like this: http://www.microsoft.com/ Then i have to escape

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.