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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:44:29+00:00 2026-06-15T17:44:29+00:00

I have a string like this in my PHP code: $string = (A)[B]C/D/E:F?G; how

  • 0

I have a string like this in my PHP code:

$string = "(A)[B]C/D/E:F?G";

how can i extract A, B, C, D, E, F, G parts from the string with regex?

i want a function, for example some_function_do_some_regex,
that take my $string as parameter and extract the
seven wanted parts from it

$parts = some_function_do_some_regex($string);
print_r($parts);

// OUTPUT
/*
Array
(
    [0] => A
    [1] => B
    [2] => C
    [3] => D
    [4] => E
    [5] => F
    [6] => G
)
*/

UPDATED:
I had to mention an important thing, but I forgot, I’m sorry.
Keep in mind that the seven parts in string (A, B, C, D, E, F, G),
are for sample and their value can change,

for example consider this:

$string = "(aaa)[bbb]ccc/ddd/eee:fff?ggg";

the output will be something like this

/*
Array
(
    [0] => aaa
    [1] => bbb
    [2] => ccc
    [3] => ddd
    [4] => eee
    [5] => fff
    [6] => ggg
)
*/

and another important note:
in the parts 1 to 6, there is no symbol character, we have a-z and 0-9 values, but for the last part (the part after the question mark), we can have any character like [ and / and anything else.

It means that the parts structure are very important.

Here is a description of every part:
Part A: everything between ( and )
Part B: everything between [ and ]
Part C: everything before first / and after ]
Part D: everything between first and second /
Part E: everything after second / and before :
Part F: everything after : and before ?
Part G: everything after ?

  • 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-15T17:44:29+00:00Added an answer on June 15, 2026 at 5:44 pm

    Thanks for Rohit Jain help. I create this answer:

    <?php
    
    $string = "(a)[b]c/d/e:f?g:part?with(non-alphabetical)[characters]!";
    preg_match_all('/([a-zA-Z0-9]+)|\?([^?]*)$/', $string, $sixparts);
    preg_match_all('/([a-zA-Z0-9]+)|.*?\?(.*)$/', $string, $sevenpart);
    
    $part_a = $sixparts[0][0];
    $part_b = $sixparts[0][1];
    $part_c = $sixparts[0][2];
    $part_d = $sixparts[0][3];
    $part_e = $sixparts[0][4];
    $part_f = $sixparts[0][5];
    $part_g = $sevenpart[2][0];
    
    echo $part_a; // a
    echo $part_b; // b
    echo $part_c; // c
    echo $part_d; // d
    echo $part_e; // e
    echo $part_f; // f
    echo $part_g; // g:part?with(non-alphabetical)[characters]!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this /blog/post1/ how can i get the post1 from
I have a JSON String like this $test='{var1:null,var3:null,status:{code:150,message:blah blah}}'; I want to access the
I have JSON string from my php script like this: var r.co = {
I have i string in my PHP-code which looks like this Bokad av Anna
I want a string replacing code i have a string like this <strong>WHAT IS
Example: I have some text, like this php code if(empty($condition)) { // work here...
I have a php code like this,going to convert it in to C#. function
I have an url like this: http://www.w3schools.com/PHP/func_string_str_split.asp I want to split that url to
I have string like this: G:\Projects\TestApp\TestWeb\Files\Upload\file.jpg How can I remove all text before Files
I have string looking like this: 'Toy Story..(II) (1995)' I want to split the

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.