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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:16:48+00:00 2026-06-10T13:16:48+00:00

$pattern = ‘#\[img (([^=\]]+)=([^]+) ?)+\]#’; preg_match_all($pattern,$blog,$matches,PREG_PATTERN_ORDER); [img size=preview click=http://text.com align=right src=pic:3378f.jpg] The code at

  • 0
$pattern = '#\[img (([^="\]]+)="([^"]+)" ?)+\]#';
preg_match_all($pattern,$blog,$matches,PREG_PATTERN_ORDER);
[img size="preview" click="http://text.com" align="right" src="pic:3378f.jpg"]

The code at the top matches the BBCode tags like above, but only returns the last attribute, when it should be returning all as per the subpatterns in my regex. What’s the deal?

  • 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-10T13:16:49+00:00Added an answer on June 10, 2026 at 1:16 pm

    For this to work you have to match the [img] block first:

    preg_match_all('#\[img(.*?)\]#s', $blog, $matches);
    

    You memorize the pattern inside the tag and use another loop to extract the parameters, using another preg:

    foreach ($matches[1] as $img) {
        preg_match_all('#\s*([^=]+)="([^"]*)"#', $img, $matches);
        // create key-pair array
        $params = array_combine($matches[1], $matches[2]);
        print_r($params);
    }
    

    Output:

    Array
    (
        [size] => preview
        [click] => http://text.com
        [align] => right
        [src] => pic:3378f.jpg
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

my pattern is: /(productimages\/)(\w*)(\/v\/)(\w*)(.jpg)/g and data: http://gskinner.com/RegExr/?2ujor and php code: $regexp = ' /(productimages\/)(\w*)(\/v\/)(\w*)(.jpg)/g';
Pattern pattern = Pattern.compile(<a>([a-zA-Z]+)</a>) Matcher matcher = pattern.matcher(<a>Text</a>); matcher.find() String str = matcher.group(); I
Pattern - <(\w+)>.+</\1> Input String - Testing <tag>some <b>idiot</b> text</tag>idiot text continue.. Now I
Pattern is Regex splRegExp = new System.Text.RegularExpressions.Regex(@[\,@,+,\,?,\d,%,.,?,*,&,^,$,(,!,),#,-,_]); All characters work except '-'. Please advise.
Call pattern: path-to-programm visual-marked-text filetype directory Example: C:\Programme\WinGrep\grep32.exe search-pattern *.sql D:\MyProject\build
regex pattern /}/ sometimes matches } and sometimes doesn't. Is there any know bug
Pattern pattern = Pattern.compile(^[a-z]+$); String string = abc-def; assertTrue( pattern.matcher(string).matches() ); // obviously fails
ViewHolder pattern improves ListView scrolling framerate, as seen in following example: https://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List14.html Is it
Pattern p2 = Pattern.compile(.*); Matcher m2 = p2.matcher(true); System.out.println(m2.matches() + [ + m2.group() +
Pattern p=Pattern.compile(( see the example pattern )); Matcher matcher=p.matcher(text); String result=matcher.replaceAll(); i.e. 2009-10-05T13:44:34+0000 2011-03-13T23:59:24+0000

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.