php - Regular Expression for this text -


i want write regex extracting numbers following text (that part of bigger text):

 switchport trunk allowed vlan 206,220,23,234,250,262,21,283,2086,296,305,323  switchport trunk allowed vlan add 334,340,342,365,380,404,41,414,42,421,434  switchport trunk allowed vlan add 461,472,499,509,29,535,544,551,552,55,595  switchport trunk allowed vlan add 642,672,690,697,701,704,711,800,2018,2020  switchport trunk allowed vlan add 2054  switchport mode trunk 

i want extract vlan numbers between switchport trunk allowed vlan , switchport mode trunk

i think pattern should like:

switchport trunk allowed vlan (\s*) ((\d+),*)+(?:.|\n) 

but don't know how extract other numbers (only first 1 matched)

i use pattern in php in preg_match function.

to extract numbers, can in following manner:-

<?php $str = ' switchport trunk allowed vlan 206,220,23,234,250,262,21,283,2086,296,305,323  switchport trunk allowed vlan add 334,340,342,365,380,404,41,414,42,421,434  switchport trunk allowed vlan add 461,472,499,509,29,535,544,551,552,55,595  switchport trunk allowed vlan add 642,672,690,697,701,704,711,800,2018,2020  switchport trunk allowed vlan add 2054  switchport mode trunk'; // original string preg_match_all('!\d+!', $str, $matches); // check digits , make array $matches print_r($matches); // print digits array echo implode(',',$matches[0]); // convert digits array comma separated string of numbers ?> 

output:- https://eval.in/596968 or https://eval.in/596974

note:- work single-line,multi-line,paragraphs (if complete data in single variable).


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -