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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:52:15+00:00 2026-06-09T03:52:15+00:00

I have a-facebook-like mentioning feature in my app. When creating posts or comments user

  • 0

I have a-facebook-like mentioning feature in my app.

When creating posts or comments user can mention other users with @ sign.
I use following jQuery plugin: http://podio.github.com/jquery-mentions-input/

Mentions are generated in the following format:
@@[Marko Kurjonen:2]
so “@@[User’s name:user_id]

Currently I have following pattern (and code):

$pattern = "/@@\[(.*):(\d*)] /ims";

$matches = array();
preg_match_all($pattern, $input, $matches);
Zend_Debug::dump($matches);
$output = preg_replace($pattern, "<a href=\"". $this->view->baseUrl("user") ."/$2\" class=\"tooltip\">$1</a>", $input);

Problem is that it only does the first mention.

Example string:

$input = "Hello @@[Markku Pelkonen:7] and @@[Marko Kurjonen:2]"

Only first user gets converted by preg_replace.

br, Marko

  • 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-09T03:52:16+00:00Added an answer on June 9, 2026 at 3:52 am

    You can use this regex:

    /@@\[([^:]*):(\d*)\]/
    

    This regex assumes that the name doesn’t contain : character.

    The original regex has 2 problems:

    • The space at the end, just after ], causes the second mention to fail to match, since it is at the end of the input. (If you remove it, the greedy quantifier will gobble up the whole input string.)
    • The * in (.*) matches 0 or more instances greedily, which means it will match as many character as possible until the next token cannot match, where it will backtrack and try to match the next token. This is why the whole input string will be gobbled up if you remove the space, as mentioned above.

    It is also possible to fix your regex a bit to make it work (apart from the solution I mentioned above):

    /@@\[(.*?):(\d*)]/s
    

    The m flag and i flag are useless here, so I remove them. You never use ^ or $ in your regex, so m flag is useless. The i flag is only useful if there are letter in the regex, which is not the case here.

    I use *? quantifier here, which is the lazy version of match 0 or more. It will match as few character as possible just for the next token to be matched.

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

Sidebar

Related Questions

I have a facebook app that I authenticate using a general-purpose authentification. Like this:
I have a facebook app that load some content with ajax, including some like
I'm creating a Facebook-like social-network website. For my wall, I have many different kind
I have a facebook like button on each of my wordpress blog posts, this
I have a little web app that uses the Facebook like widget. This page
I am doing this in order to have Facebook like button in my page:
I have multiple Facebook like boxes in one page. Suppose, I have two dives
I have a Facebook like that links to a page on witch I don't
I have a facebook like button on http://www.hotsear.ch , but will not show a
Possible Duplicate: Google plus api for posting on wall like facebook I have checked

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.