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

  • Home
  • SEARCH
  • 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 4092982
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:33:38+00:00 2026-05-20T19:33:38+00:00

$text = ‘Lorem Ipsum’; $re = ‘/(?<AA>Any)|(?<BB>Lorem)/ui’; $nMatches = preg_match_all($re, $text, $aMatches); $aMatches will

  • 0
$text = 'Lorem Ipsum';
$re = '/(?<AA>Any)|(?<BB>Lorem)/ui';
$nMatches = preg_match_all($re, $text, $aMatches);

$aMatches will contain the following:

Array (
    [0] => Array (
            [0] => Lorem
        )

    [AA] => Array (       //  do not include to result matches array
            [0] =>        //  because have not match for this part
        )

    [1] => Array (
            [0] => 
        )

    [BB] => Array (
            [0] => Lorem
        )

    [2] => Array (
            [0] => Lorem
        )
)

Question:
Is it possible to return the array without nodes for named parts that have no matches?

 Array (
        [0] => Array (
                [0] => Lorem
            )

        {there was [AA] && [1], but have not returned because empty} 

        [BB] => Array (
                [0] => Lorem
            )

        [1] => Array (        // changed to 1
                [0] => Lorem
            )
    )
  • 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-20T19:33:39+00:00Added an answer on May 20, 2026 at 7:33 pm

    Specifically for regex, you can see @Stephan’s answer. More generally, when just manipulating arrays, you can use a combination of array_map and array_filter to do that. array_filter without a callback will strip the values that evaluates to false (== false not === false, see empty).

    For a single-level array:

    $array = array('foo', '', 'bar');
    $clean_array = array_filter($array);
    

    For a 2D array:

    $clean_array = array_filter(array_map('array_filter', $array));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Text in textbox and combobox do not render as they should be. Some letter
Text in the sidebar is not showing on load in Chrome or Safari at
Text : aaaa Pattern : aa then will two match: aa(0,1), aa(2,3) if I
text with apstrophe is not working in the twitter. Now i am using this
text<br> text2<br> text3<br/> br tags may be self closing or not. would it be
Text file 1 has the following format: 'WORD': 1 'MULTIPLE WORDS': 1 'WORD': 2
The text printed using geom_text is not very clear. How can I make it
Text box is defined in following code: <TextBox Grid.Row=2 IsReadOnly={Binding IsDescriptionReadOnly} AcceptsReturn=True TextWrapping=Wrap VerticalScrollBarVisibility=Auto
My text file contents similar to following lines xcopy Source Destination /y /r /Q
The text for each cell in a UITableView is not being displayed, and I

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.