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
Matt
3,8969 gold badges38 silver badges37 bronze badges
1 Answer 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
timdream
5,9225 gold badges25 silver badges24 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js
The Event type:page,event? I think you need to write a full function instead of a single line of regexp