regexp match groups

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

Steve James
Ebase User
Posts: 331
Joined: Mon Mar 10, 2014 8:34 am

regexp match groups

#1

Postby Steve James » Tue Jun 28, 2016 1:05 pm

Hi, I'm trying to pull out some structured data from a text file (SNMP walk).

My regex is working and grouped into 4. The intention is to pull out all the matches (working) into an array and then simply pull out the 2nd and 4th match group to get the 2 values I require.

var reg = /(.iso.3.6.1.2.1.17.4.3.1.2)(.{3,})( = )(.{1,})/g;

I can loop through the matches but have been unable to pull out the 2nd and 4th match via regex.

I can pull out the values by looping the array and a replace on the 1st group then a split on the " = " but it is clunky.

In dotnet I can do this simply. Has anyone any ideas?

Thanks
0 x

Steve James
Ebase User
Posts: 331
Joined: Mon Mar 10, 2014 8:34 am

#2

Postby Steve James » Tue Jun 28, 2016 2:01 pm

Tempted fate by posting but at least this may be of use for someone else i the future.

I've often not quite worked out when to use a "for"; a "for each"or a "while"

The following works

Code: Select all

var r = new RegExp("(.iso.3.6.1.2.1.17.4.3.1.2.)(.{3,})( = )(.{1,})","g");
 
 while((result = r.exec(content)) != null)
 {
   output = output + result[2] + ' ## ' + result[4] + '\r\n';
 }
0 x


Who is online

Users browsing this forum: No registered users and 19 guests