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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:32:29+00:00 2026-06-12T08:32:29+00:00

Although I can find a lot of tutorials on regular expressions, it remains above

  • 0

Although I can find a lot of tutorials on regular expressions, it remains above my grasp. The regular expression that I want to create is simple (judged by what I see in some of the examples), but I simply can not figure it out.

I want to do a simple replacement as follows:

  1. I have image metadata saved in a MySQL table, with fields: id, name, title and alt.
  2. In my content, I want to write [[IMAGE:1:right]]content here[[image:2:left]].
  3. I want to get the matches of the ID (the digit) and the float (left or right) and replace the entire string with the image floated left or right, retrieved by the ID from the database table.

Here is my attempt:

preg_match("/^\[\[image:(\d+):(left|right)\]\]+/i", "[[IMAGE:1:right]]content here[[image:2:left]]", $matches);

This gives me the return of:

Array ( [0] => [[IMAGE:1:right]] [1] => 1 [2] => right )

So, it finds one, but I want it to find ALL of them, as I may have more than one image in a post. As far as I can tell, the + there should match all entries, and the i should match case insensitive. It appears as if the case insensitive way works, but I get only one return.

Could someone please let me know what I am doing wrong?

  • 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-12T08:32:30+00:00Added an answer on June 12, 2026 at 8:32 am

    That’s not quite how it works. That + only applies to the token immediately before it – the ]. You want to make the match global in Perl vernacular, which for PHP (which I think you’re using?) means calling the function preg_match_all(). You’ll also have to remove the ^, as only one of the images occurs at the beginning of the string.

    Also, [ and ] are special characters in regex – so please escape them when you want a literal bracket by writing \[\[ and \]\].

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

Sidebar

Related Questions

I have searched a lot of threads but i can't find any answer that
Although iOS provides a lot of useful string methods, I can't find a good
I've seen from some sources that although you can make an exe or mac
How can I create a JTable with a row header? This question seems simple
I'm stuck on a RegEx problem that's seemingly very simple and yet I can't
Although this is pretty basic, I can't find a similar question, so please link
It seems that all of the documentation I can find about OpenGL-ES says something
I have a question, although I can't really go into specifics. Will the following
I have the following razor template html, although I can't figure out how to
Although obviously not all scenarios can be covered by a single design, is it

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.