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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:26:00+00:00 2026-06-12T17:26:00+00:00

I am trying to match a semi dynamically generated string. So I can see

  • 0

I am trying to match a semi dynamically generated string. So I can see if its the correct format, then extract the information from it that I need. My Problem is I no matter how hard I try to grasp regex can’t fathom it for the life of me. Even with the help of so called generators.

What I have is a couple different strings like the following. [@img:1234567890] and [@user:1234567890] and [@file:file_name-with.ext]. Strings like this pass through are intent on passing through a filter so they can be replaced with links, and or more readable names. But again try as I might I can’t come up with a regex for any given one of them.

I am looking for the format: [@word:] of which I will strip the [, ], @, and word from the string so I can then turn around an query my DB accordingly for whatever it is and work with it accordingly. Just the regex bit is holding me back.

  • 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-12T17:26:01+00:00Added an answer on June 12, 2026 at 5:26 pm

    Not sure what you mean by generators. I always use online matchers to see that my test cases work. @Virendra almost had it except forgot to escape the [] charaters.

    /\[@(\w+):(.*)\]/
    

    You need to start and end with a regex delimeter, in this case the ‘/’ character.

    Then we escape the ‘[]’ which is use by regex to match ranges of characters hence the ‘[‘.

    Next we match a literal ‘@’ symbol.

    Now we want to save this next match so we can use it later so we surround it with ().

    \w matches a word. Basically any characters that aren’t spaces, punctuation, or line characters.

    Again match a literal :.

    Maybe useful to have the second part in a match group as well so (.*) will match any character any number of times, and save it for you.

    Then we escape the closing ] as we did earlier.

    Since it sounds like you want to use the matches later in a query we can use preg_match to save the matches to an array.

    $pattern = '/\[@(\w+):(.*)\]/';
    $subject = '[@user:1234567890]';
    preg_match($pattern, $subject, $matches);
    print_r($matches);
    

    Would output

    array(
        [0] => '[@user:1234567890]', // Full match
        [1] => 'user', // First match
        [2] => '1234567890' // Second match
    )
    

    An especially helpful tool I’ve found is txt2re

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

Sidebar

Related Questions

I am trying to match words driven from a database in a string input
I am trying to match a md5 has (generated through php) to its original
I'm trying to match a string with a variable, this variable comes from a
I'm trying to match a string and then use grouping to create a new
I'm trying to match a string against a pattern, but there's one thing I
I'm trying to match the '12345' from a url in this form: http://domain.com/folder/title_of_this_12345 So
I am trying to match on a string that begins with ./media I have
I'm trying to match the following items in the string pcode : u followed
Im trying to match only one of each node with a generic match. Can
I'm trying to match exactly the following format: +639201112222 09201112222 and this is all

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.