Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
JavaScript RegEx Parse Command Line into Array
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jaye  
View profile  
 More options Nov 4, 3:27 pm
From: Jaye <jspe...@yahoo.com>
Date: Wed, 4 Nov 2009 12:27:25 -0800 (PST)
Local: Wed, Nov 4 2009 3:27 pm
Subject: JavaScript RegEx Parse Command Line into Array
I need a javascript method that will parse a command line instruction
into an array of pairs.  The method should utilize the javascript
String.match or other regular expression enabled methods to implement
the parse.  The regex should be implemented in a very terse
instruction.  The deliverable for this project is a terse javascript
method that will parse a collection of test values and produce the
appropriate array output.  The test cases can be found at
http://spreadsheets.google.com/pub?key=trvoEkjsIMF1NwBJb7vyEKw&single...

I posted the micro project on @oDesk http://bit.ly/3TgOJX .  Probably
an easy task for you guys so let me know if you can help.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eugeny.Sattler@gmail.com  
View profile  
 More options Nov 5, 5:48 am
From: "Eugeny.Satt...@gmail.com" <eugeny.satt...@gmail.com>
Date: Thu, 5 Nov 2009 02:48:31 -0800 (PST)
Local: Thurs, Nov 5 2009 5:48 am
Subject: Re: JavaScript RegEx Parse Command Line into Array
The nut is cracked! Still it is two step check. Judge yourself if it
is terse or not :)

1. The main regex.
Most of the examples including listed below

keyword:model train locomotive
keyword:redline
sellerid:allwheels2go
keyword:truck sellerid:allwheels2go
keyword:model train locomotive minbid:1
keyword:model train locomotive minbid:1 maxprice:50
categoryid:19175 minbid:1
categoryid:19175 desc:"flower:grown"
keyword:redline sort:bidcount
keyword:chevy truck maxdistance:100 miles
sellerid:bob,john,james,jim
sellerid:bob sellerid:john sellerid:james sellerid:jim

will be covered by regex
(\w+)\:\"?([^\r\n]+?)(?=(?:\"|\x20\w+\:|[\r\n]+|\Z))

if you grep through the line (repeat the search cyclically)

2. The check.
Now we have out of order things like

model train locomotive  //no command at all
"flower:grown"          //the value itself contains colon

not covered by our regex.

Not to get stuck on this, you FIRST need to check if your subject
string  against

^(([a-z0-9\x20]+)|\"([a-z0-9:]+)\")$

And if that matches, use backreference $1 or $2 as collected value.
The one which is not empty is what you need. That'll be the value.
Prepend that value with "keyword" or whatever your setting is.

--------------------

What i described in step2 should in fact be the first check because

"flower:grown"

on a line by itself can be matched by the main regex and therefore
"flower" will be considered as command and "grown" as value, while
this is undesired. To avoid this, don't feed the subject string to the
main regex if the check gives you positive alert.

--
Regards,     Eugeny


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google