I'm rewriting a PHP web page into Lucee.
Original PHP Code:
while ( !feof ($fp) ) {
$line = fgets ($fp, 1024);
# Look for features in the output. You will see stuff like
# Users of Allegro_Viewer: (Total of 5 licenses available
if ( preg_match('/(Users of) (.*)(\(Total of) (\d+) (.*) (Total of) (\d+) /i', $line, $out) && !eregi("No such feature exists", $line) ) {
$i++;
$license_array[$i]["feature"] = $out[2];
$license_array[$i]["num_licenses"] = $out[4];
$license_array[$i]["licenses_used"] = $out[7];
}
}
I'm looking to loop over this response text:
lmutil - Copyright (c) 1989-2019 Flexera. All Rights Reserved. Flexible License Manager status on Sat 10/15/2022 11:19 [Detecting lmgrd processes...] License server status: 27002@someservername License file(s) on someservername: C:\SIMULIA\License\2022.HF2\win_b64\code\bin\simulialm.lic: someservername: license server UP (MASTER) v11.16.5 Vendor daemon status (on someservername): ABAQUSLM: UP v11.16.5 Feature usage info: Users of pydriver: (Total of 2 licenses issued; Total of 0 licenses in use) Users of cae: (Total of 2 licenses issued; Total of 0 licenses in use) Users of abaqus: (Total of 41 licenses issued; Total of 0 licenses in use) Users of ams: (Total of 1 license issued; Total of 0 licenses in use) Users of aqua: (Total of 41 licenses issued; Total of 0 licenses in use) Users of cosim_acusolve: (Total of 1 license issued; Total of 0 licenses in use);
so that I can pull out the Users of...
into an array (example shown below).
Users of pydriver: (Total of 2 licenses issued; Total of 0 licenses in use)
Users of cae: (Total of 2 licenses issued; Total of 0 licenses in use)
Users of abaqus: (Total of 41 licenses issued; Total of 0 licenses in use)
Users of ams: (Total of 1 license issued; Total of 0 licenses in use)
Users of aqua: (Total of 41 licenses issued; Total of 0 licenses in use)
Users of cosim_acusolve: (Total of 1 license issued; Total of 0 licenses in use)
I'm using the existing regex (which works under PHP) but not sure if it's right for the format my data is coming in under Lucee compared to how the original PHP code received it's response. For example, I think in PHP, the text is broken up by line whereas in Lucee, it's one long text string without carriage returns.
My regx is '\/(Users of) (.*)(\(Total of) (\d+) (.*) (Total of) (\d+) \/i'
but I'm not clear on how to use it to pull out the data I need. I've tried cfloop, refindnocase, and reMatchNoCase but without success.
Ultimately I asking for help this PHP code block but I'd like to understand how to use regex to extra the data Lucee 5.x?
CODE I'VE TRIED
lmutil_response = 'lmutil - Copyright (c) 1989-2019 Flexera. All Rights Reserved. Flexible License Manager status on Sat 10/15/2022 11:19 [Detecting lmgrd processes...] License server status: 27002@someservername License file(s) on someservername: C:\SIMULIA\License\2022.HF2\win_b64\code\bin\simulialm.lic: someservername: license server UP (MASTER) v11.16.5 Vendor daemon status (on someservername): ABAQUSLM: UP v11.16.5 Feature usage info: Users of pydriver: (Total of 2 licenses issued; Total of 0 licenses in use) Users of cae: (Total of 2 licenses issued; Total of 0 licenses in use) Users of abaqus: (Total of 41 licenses issued; Total of 0 licenses in use) Users of ams: (Total of 1 license issued; Total of 0 licenses in use) Users of aqua: (Total of 41 licenses issued; Total of 0 licenses in use) Users of cosim_acusolve: (Total of 1 license issued; Total of 0 licenses in use) Users of cosim_direct: (Total of 1 license issued; Total of 0 licenses in use) Users of cse: (Total of 1 license issued; Total of 0 licenses in use) Users of design: (Total of 41 licenses issued; Total of 0 licenses in use) Users of euler_lagrange: (Total of 1 license issued; Total of 0 licenses in use) Users of gpgpu: (Total of 1 license issued; Total of 0 licenses in use) Users of multiphysics: (Total of 1 license issued; Total of 0 licenses in use) Users of parallel: (Total of 16384 licenses issued; Total of 0 licenses in use) Users of cfd: (Total of 41 licenses issued; Total of 0 licenses in use) Users of explicit: (Total of 41 licenses issued; Total of 0 licenses in use) Users of foundation: (Total of 41 licenses issued; Total of 0 licenses in use) Users of standard: (Total of 41 licenses issued; Total of 0 licenses in use) Users of cse_token: (Total of 41 licenses issued; Total of 0 licenses in use)';
Attempt A
local.data.regx = '/(Users of) (.*)(\(Total of) (\d+) (.*) (Total of) (\d+) /i';
myArray = listToArray(local.data.qryLicenseServerStatusByServerIDAndPort.lmutil_response,local.data.regx,false,true);
dump(myArray);
Attempt B
local.data.regx = '/(Users of) (.*)(\(Total of) (\d+) (.*) (Total of) (\d+) /i';
x = reMatchNoCase(local.data.regx, local.data.qryLicenseServerStatusByServerIDAndPort.lmutil_response)
dump(x);
Yer on the right track with reMatchNoCase
. although probably no need for the NoCase
bit.
Yer regex pattern seems overly complicated to me, and I think this is all you need:
s = "lmutil - Copyright (c) 1989-2019 Flexera. All Rights Reserved. Flexible License Manager status on Sat 10/15/2022 11:19 [Detecting lmgrd processes...] License server status: 27002@someservername License file(s) on someservername: C:\SIMULIA\License\2022.HF2\win_b64\code\bin\simulialm.lic: someservername: license server UP (MASTER) v11.16.5 Vendor daemon status (on someservername): ABAQUSLM: UP v11.16.5 Feature usage info: Users of pydriver: (Total of 2 licenses issued; Total of 0 licenses in use) Users of cae: (Total of 2 licenses issued; Total of 0 licenses in use) Users of abaqus: (Total of 41 licenses issued; Total of 0 licenses in use) Users of ams: (Total of 1 license issued; Total of 0 licenses in use) Users of aqua: (Total of 41 licenses issued; Total of 0 licenses in use) Users of cosim_acusolve: (Total of 1 license issued; Total of 0 licenses in use);"
matches = s.reMatch("(Users of[^)]+\))")
writeDump(matches)
If there's a LF between each match, that'd be better to match on than the )
, that said.
One other thing to note here, you are using PHP-format pattern delimiters (/
), which isn't a thing in CFML. A pattern is just a string. These docs are a bit of a mess, and are for ColdFusion and not Lucee, but it should be the same on Lucee: ColdFusion: Regular expression syntax.
Also I write extensively on all the ins and outs of CFML Regexes on my blog (this lot is from years ago, but should still be largely correct): Regular expressions in CFML (part 8: the rest of CFML's support for regular expressions) (includes links back to previous 7 parts too.