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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:20:21+00:00 2026-06-10T00:20:21+00:00

Just wondering if someone can help me understand why my regular expression is matching

  • 0

Just wondering if someone can help me understand why my regular expression is matching a particular line. Here’s the input data:

         Array ( [0] => [24;1H [24;16H [24;1H [?25h [24;16H [24;16Hshow vlans [24;16H [?25h [24;26H [24;0H E [24;1H [24;26H [24;1H [2K [24;1H [?25h [24;1H [1;24r [24;1H [1] => Status and Counters - VLAN Information [2] => [3] => Maximum VLANs to support : 256 [4] => Primary VLAN : MANAGEMENT [5] => Management VLAN : [6] => [7] => VLAN ID Name | Status Voice Jumbo [8] => ------- -------------------------------- + ---------- ----- ----- [9] => 1 DEFAULT_VLAN | Port-based No No [10] => 3 MANAGEMENT | Port-based No No [11] => 8 SERVER_VLAN | Port-based No No [12] => 16 iLOSERS | Port-based No No [13] => 20 BACS_VLAN | Port-based No No [14] => 33 VLAN_33 | Port-based No No [15] => 64 ISM_VLAN | Port-based No No [16] => 65 DSLAM1 | Port-based No No [17] => 80 VOIP_VLAN | Port-based No No [18] => 96 DZONE | Port-based No No [19] => 128 BACNET_128 | Port-based No No [20] => 131 BACNET_131 | Port-based No No [21] => [22] => [23] => [1;24r [24;1H [24;1H [2K [24;1H [?25h [24;1H [24;11# ) 

And here’s my code:

  $vlandetailsArray = array();
  foreach ($data as $vlandetails) {

   $pattern = '/(\s+)([0-9]*)(\s+)([a-z_0-9]*)(\s*)(\|)(\s+)([a-z0-9_-]*)(\s*)(\w*)(\s*)(\w*)/i';
   if (preg_match($pattern, $vlandetails, $matches)) {
      echo 'raw data is: '.($vlandetails).'<br>';   
      echo 'results from print_r:';
      print_r($matches[2]);       
      echo '<br>VlanId is: '.$matches[2].'<br>';
      } //end if
    } //end for

Here are the results of the print / echo statements:

raw data is: VLAN ID Name | Status Voice Jumbo
results from print_r:
VlanId is:
raw data is: 1 DEFAULT_VLAN | Port-based No No
results from print_r:1
VlanId is: 1
raw data is: 3 MANAGEMENT | Port-based No No
results from print_r:3
VlanId is: 3
raw data is: 8 SERVER_VLAN | Port-based No No
results from print_r:8

My question is why the first item gets matched when it doesn’t start with a number?
Would you mind pointing out where my bug is or what I’m not understanding?

Thanks.

  • 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-10T00:20:23+00:00Added an answer on June 10, 2026 at 12:20 am

    Change the ([0-9]*) in the regex to ([0-9]+)

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

Sidebar

Related Questions

just wondering if someone can help me make this code work properly and be
Just wondering if someone can help me figure out why my menu is doing
just wondering if someone can help me with a Javascript principle. I'm guessing this
Just wondering if someone can help me out with this quickly. I have a
Just wondering if someone can help me code the following. I want to use
Just wondering if someone can help me with the following issue. I want to
I was just wondering if someone can help with an annoyance I have with
Just wondering if someone could help me with a very simple SQL query. I
I'm just wondering if someone could point me in the right direction here, I
I'm wondering if someone can help me with this. I have three TabPanels depending

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.