Faulty regular expression for seconds extraction - but cannot see what is wrong... :S

Hi there, in my site I have a console which optionally outputs any sql queries run, plus various debugging info. Nw when running the query which I want to see the timeout info of - the following snippet of script is used.
The result being that the sql query’s info is not always sent via xml. The following code attempts to parse the sql string, to get the line mentioning the time taken to process - saving that to rcnt. Then if match() does not return null, it is supposed to get the time taken in seconds. note the two lines in bold below. after this it is supposed to replace a %SEC% flag in the innerHTML of the topmost field (id cntf) in the data table.

                    if (sql != undefined) {
[B]                        var rcnt = sql.match(/^line [\\d]+[\\/a-z\\. ]*[\\d]+.[\\d]+ seconds.$/mgi);[/B]
                        if (rcnt !== null) {
[B]                            var ncnt = rcnt[0].match(/[\\d]*.[\\d]*/g);[/B]

the value of sql is shown below, returned from ajax - followed by the value of rnct (which is shown to be null):

‘0’ => "SELECT
UPPER(SC.text_ServiceDescription) AS Service,
') AS Country,
)) AS Region,
UPPER(S.text_SupplierName) AS Supplier,
WHEN 0 THEN ‘Premium’
WHEN 1 THEN ‘Paused’
WHEN 2 THEN ‘Trial’
WHEN 3 THEN ‘Inactive’
WHEN 4 THEN ‘Freemium’
') AS Status,
SC.bigint_PrimaryAttributeKey = 0 OR SA1.text_AttributeValue = NULL,
') AS Prim_Att_Val
4_servicesuppliers SS
INNER JOIN 2_servicescatalogue SC ON (SS.bigint_ServiceID = SC.bigint_ServiceID)
INNER JOIN 1_regions R ON (SS.bigint_RegionID = R.bigint_RegionID)
INNER JOIN 5_suppliers S ON (SS.bigint_SupplierID = S.bigint_SupplierID)
LEFT JOIN 3_serviceattributes SA0 ON (SC.bigint_PrimaryAttributeKey = SA0.bigint_AttributeID AND SC.bigint_ServiceID = SA0.bigint_AttributeServiceID)
LEFT JOIN 3_serviceattributes SA1 ON (SA0.text_AttributeDescription = SA1.text_AttributeDescription AND SC.bigint_ServiceID = SA1.bigint_AttributeServiceID)
LEFT JOIN 1_regions R0 ON (R.bigint_ParentRegionID = 0 AND R.bigint_RegionID = R0.bigint_ParentRegionID)
LEFT JOIN 1_regions R1 ON (R.bigint_ParentRegionID != 0 AND R.bigint_ParentRegionID = R1.bigint_RegionID)
LEFT JOIN 9_supplierattributes SA3 ON (S.bigint_SupplierID = SA3.bigint_SupplierID AND SC.bigint_ServiceID = SA3.bigint_ServiceID AND ((R.bigint_RegionID = SA3.bigint_RegionID OR R.bigint_ParentRegionID = SA3.bigint_RegionID) OR (R0.bigint_RegionID = SA3.bigint_RegionID OR R0.bigint_ParentRegionID = SA3.bigint_RegionID) OR (R1.bigint_RegionID = SA3.bigint_RegionID OR R1.bigint_ParentRegionID = SA3.bigint_RegionID)) AND SA1.bigint_AttributeID = SA3.bigint_AttributeID)
LEFT JOIN 3_serviceattributes SA2 ON (SA3.bigint_AttributeID = SA2.bigint_AttributeID AND SC.bigint_ServiceID = SA2.bigint_AttributeServiceID)
WHERE SA2.text_AttributeValue IS NULL
GROUP BY Service, Region, Supplier
ORDER BY Service ASC, Region ASC, Supplier ASC;

$_POST = Array
[orderby] => ORDER BY Service ASC, Region ASC, Supplier ASC
[where] => WHERE
[groupby] => GROUP BY Service, Region, Supplier
[groupcnct] => ,Country,Status,Prim_Att_Val

Line 829 in /var/www/performatix.co/production/scripts/ajax_services.php executed in 0.089391946792603 seconds.
‘0’ …

However, I am struggling to match the bold, italic and underlined with regular expressions. What am I doing wrong here? 0o
sincerely - Pierre.


So in other words, in this string:

Line 829 in /var/www/performatix.co/production/scripts/ajax_services.php executed in 0.089391946792603 seconds.

you want to match:


Is that correct?

Is it just this one case you are trying to match, or is there a pattern (e.g. “{Line no} {file path} executed in {time} seconds.”) whereby you are trying to get the time?

yes pullo - it was just one case… i resolved it by making sure it was that line and specific ajax request then repaired the regex match as follows…
issue was resolved by changing the regex matches and adjusting the javascript to:

                    if (sql != undefined) {
                        var rcnt = sql.match(/(line 829[a-z\\/_. ]+)[0-9]+\\.[0-9]+/g);
                        if (sql.toLowerCase().indexOf('line 829')==-1) salert(sql);
                        if (rcnt !== null) {
                            var text = document.getElementById("cntf").innerHTML;
                            document.getElementById("cntf").innerHTML = text.replace(/%SEC%/g,rcnt[0]);

Glad you got it sorted out.
Thanks for taking the time to report back :slight_smile: