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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:29:30+00:00 2026-05-26T11:29:30+00:00

This seems like it must be so simple, but regular expressions are extremely confusing

  • 0

This seems like it must be so simple, but regular expressions are extremely confusing to me. I am grabbing $_GET variables that will look like typeX, optionX, groupX, etc. where X equals any positive whole integer. I need to then split the string at the integer so that type1 becomes an array of “type and “1”, however type10 must become an array of “type and “10” not “type” and “1” and “0”.

I am wholly unfamiliar with regex patterns but ended up coming up with:

$array = preg_split("#\\d+#", $key, -1, PREG_SPLIT_NO_EMPTY);
print_r($array);

but it just removed the number from the end rather than split the string into two arrays as was shown by the result:

Array ( [0] => type )

Also, I am unsure as if this would further split the number ten into a one and a zero, which I don’t want. I feel like this is probably a mind numbingly simple solution but I am spinning in circles here.

  • 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-05-26T11:29:30+00:00Added an answer on May 26, 2026 at 11:29 am

    You should use the PREG_SPLIT_DELIM_CAPTURE flag to capture the group which you made the split on. Here’s an example:

    <?php
    
    $key= "group12";
    $pattern = "/(\d+)/";
    
    $array = preg_split($pattern, $key, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
    print_r($array);
    
    ?>
    

    Note that you combine several flags using the | “bitwise or” operator.

    Output:

    Array
    (
        [0] => group
        [1] => 12
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems like a simple question, but I can't find it with the Stack
This seems like it should have a simple solution but I can't seem to
This seems like a noob question, but the simple answer is eluding me. I
ok, this seems like it should be really simple but Im a bit confused:
This seems like it should be dead simple, so I must be missing something.
this seems like very simple maths but somehow, my brain cant think ... i
This seems like a simple task or a repeat, but bear with me-- I've
I feel like this must be very simple, but for some reason I am
Ok I must be overlooking something extremely simple but I am lost. Given this
This seems like a pretty softball question, but I always have a hard time

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.