Regex and array variables

85 views
Skip to first unread message

Alexander S Argollo

unread,
Jun 26, 2013, 9:10:08 AM6/26/13
to comman...@googlegroups.com
Hi Guys. I am trying to work with Regex to get a strings and building a array with those parameters but i have a problem to form the array. I try to explain what exacly the problem:

My Regex command was : 
target string on feedback: [409f,8c9b,dece]
NodesArrayRegex: /\[(\d+\w+),(\d+\w+),(\d+\w+)]/i,
var nodesArray = [];
nodesArray= ZB.NodesArrayRegex.exec(theMsg);

i tested it and saw that is running well on the 1st switch case structure:

case "3": if (ZB.NodesArrayRegex.test(theMsg)) . I saw using CF.LOG that this part was found/running

But when i trying to see the variable nodeArray using the CF.LOG on the 2st structure below:

switch(nodesArray[0]) { 
case "[409f,8c9b,dece]": if(ZB.trace) CF.log("ZB.feedback: the Match string Length was found **** The value is= "+nodesArray[0]);

the switch default was reached  i was able to see that the way to present the nodeArray[0] is not good. Maybe i cant make it. but i cant know how to do it.

LOG Result :
 TypeError: 'null' is not an object (evaluating 'nodesArray[0]')


Alexander S Argollo

unread,
Jun 26, 2013, 8:22:12 PM6/26/13
to comman...@googlegroups.com
Guys. I was found the problem. I can see that my Regex formula was not reached the Str. I was check it on gethifi (http://www.gethifi.com/tools/regex) and there appear that was good. 

I want to build the array with [Command, length value, param1, param2] to use it on another function (command).

When i using on Regex array the simple Regex formula my feedback was running well. But when i using the complex formula it is not running good. Could you see below:

Simple formula: NodeMgmtRegex: /(Node_GetNumNodes|Node_GetNode)/i, // runnig very well.
NodesRegex: /methodName.(\w+).+\length=.(\d).*\[(\d+\w+),(\d+\w+),(\d+\w+)]/i,

My string: <zbpPacketResponse><Object>ZBP_Node</Object><methodName>Node_GetNumNodes</methodName><Arguments><Argument type="ushort">3</Argument><Argument type="QVector&lt;ushort&gt;" length="3">[409f,8c9b,1f2a]</Argument></Arguments><id>19900</id><session>7f360d5e-66d0-4daf-b9fe-806c71f8ed8f</session></zbpPacketResponse>

when i made the regex.exec to add the string array on my variable "matches" and after check it on switch/case the problem occour:

var matches =theMsg.match(ZB.NodesRegex)

switch(matches[1]) { ......

Error on log:
TypeError: 'null' is not an object (evaluating 'matches[1]')

Jarrod Bell

unread,
Jun 26, 2013, 8:32:13 PM6/26/13
to comman...@googlegroups.com
You have a stray backslash in your regex before "length". Correct one is:
methodName.(\w+).+length=.(\d).*\[(\d+\w+),(\d+\w+),(\d+\w+)]

There is a regex tester built right into guiDesigner that you might want to checkout. Open it from the toolbar.

You should also be adding error checking code so that you don't get crashes from malformed data.

if (matches !== null && matches.length == 5) {

Regards,

Jarrod Bell
CommandFusion
www.commandfusion.com


--
You received this message because you are subscribed to the Google Groups "CommandFusion Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commandfusio...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Alexander S Argollo

unread,
Jun 27, 2013, 6:33:03 PM6/27/13
to comman...@googlegroups.com
Hi Jarrod, thanks a lot for your assistance. I changed as you told me but still wrong. Could you see the log below:

TypeError: 'null' is not an object (evaluating 'matches[1]')

i have declared the variable matches as: var matches =ZB.NodesRegex.exec(theMsg);

as i told you if i just change the Regex pattern as a simple string to find : 
NodeMgmtRegex: /(Node_GetNumNodes|Node_GetNode)/i,

I can reached the Switch/Case conditions in the same part of the JS code. 
Are you have any idea to fix it?

thanks a lot.








2013/6/26 Jarrod Bell <jar...@commandfusion.com>

--
You received this message because you are subscribed to a topic in the Google Groups "CommandFusion Software" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/commandfusion/XnZc3wAXs6Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to commandfusio...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
atenciosamente,
Alexander S Argollo
11-99468494
mailto: alexande...@gmail.com

Jarrod Bell

unread,
Jun 27, 2013, 8:14:40 PM6/27/13
to comman...@googlegroups.com
Add some logging such as CF.logObject(matches) and see what's going on. You need to do more debugging of the objects to get a better idea of whats happening.
Also see our debugging documentation for details on how to dig even deeper into the call stack:
http://commandfusion.com/docs/scripting/debug.html


Regards,

Jarrod Bell
CommandFusion
www.commandfusion.com


Alexander S Argollo

unread,
Jun 28, 2013, 9:50:40 PM6/28/13
to comman...@googlegroups.com
Hi Jarrod, i checked that the object is null, after i include the CF.logObject, as you can see below the the object was null:

the Object was defined as: var matches =ZB.NodesRegex.exec(theMsg);
The Regex Pattern was defined as : NodesRegex: /methodName.(\w+).+length=.(\d).*\[(\d+\w+),(\d+\w+),(\d+\w+)]/i,
i inclued the code trigger as you told me, as: if (matches!=null && matches.length>0) { ....
The Object (CF.logObect) inspection was: if(ZB.trace) CF.logObject("ZB.feedback: The Object matches was not found= "+matches);

The result was:  > ZB.feedback: The Object matches was not found= null
 
Please, could you give more idea? I didn't have any idea to fix it,



2013/6/27 Jarrod Bell <jar...@commandfusion.com>

Jarrod Bell

unread,
Jun 29, 2013, 8:41:46 AM6/29/13
to comman...@googlegroups.com
You are missing an escape char (backslash) before the last closing square bracket. You need to test your regex in guiDesigner or some other regex tool.
methodName.(\w+).+length=.(\d).*\[(\d+\w+),(\d+\w+),(\d+\w+)\]


Regards,

Jarrod Bell
CommandFusion
www.commandfusion.com


Alexander S Argollo

unread,
Jun 29, 2013, 9:41:48 AM6/29/13
to comman...@googlegroups.com
Hi Jarrod, i finished another tests with Regex pattner, the last one have that i used had a errors to find all the string, could you see below, after it is running well. On this i scape the special caracter:

NodesRegex: /methodName.(\w*).+length=.(\d)..\[([\d|\w][\d|\w][\d|\w][\d|\w]),([\d|\w][\d|\w][\d|\w][\d|\w]),([\d|\w][\d|\w][\d|\w][\d|\w])\]/i,

Thanks a lot for your assistance!!!
Without you I would not have succeeded !!!!
BR
Alex


2013/6/29 Jarrod Bell <jar...@commandfusion.com>

Jarrod Bell

unread,
Jun 29, 2013, 8:07:43 PM6/29/13
to comman...@googlegroups.com
FYI, you dont need to use \d in some of your regex, \w will match letters, numbers, and underscores.

NodesRegex: /methodName.(\w*).+length=.(\d)..\[(\w{4}),(\w{4}),(\w{4})\]/i,


Regards,

Jarrod Bell
CommandFusion
www.commandfusion.com


alexande...@gmail.com

unread,
Jun 30, 2013, 6:26:27 AM6/30/13
to comman...@googlegroups.com
Hi Jarrod.
I'll use it. thanks a lot.
BR
Alex
Enviado do meu smartphone BlackBerry 10.
De: Jarrod Bell
Enviada: sábado, 29 de junho de 2013 21h07
Assunto: Re: Regex and array variables
Reply all
Reply to author
Forward
0 new messages