1

I'm working on a function to parse a text field. Below are some scenarios:

In: "about"
Result: var keywords = "about"
In: "type:page " (notice the space)
Result: var types = ["page"];
In: "type:page about"
Result: var types = ["page"], keywords = "about";
In: "type:page,event The Event"
Result: var types = ["page", "event"], keywords = "The Event";

Can someone point me in the right direction as to how I'd parse this using RegEx?

asked Sep 2, 2011 at 10:25
1
  • How about The Event type:page,event? I think you need to write a full function instead of a single line of regexp Commented Sep 2, 2011 at 10:31

1 Answer 1

1
 function inOut (input) {
 var output = {};
 if (input.indexOf('type:') !== -1) {
 output.types = input.replace(/^.*type:([^ ]+).*$/, '1ドル').split(',');
 output.keywords = input.replace(/^(.*)type:([^ ]+)(.*)$/, '1ドル 3ドル');
 } else {
 output.keywords = input;
 }
 return output;
 }

Try this?

answered Sep 2, 2011 at 10:36
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.