Javascript regex match -
I am working on a function to parse a text field. Below are some scenarios:
In: "about" results: var keyword = "about" in: "Type: page" (focus on location) results: var type = ["Page"] ; In: "Type: About page" results: var type = ["page"], keyword = "about"; In: "Type: Page, Event Event" result: var type = ["Page", "Event"], keyword = "Event"; Does anyone tell me in the right direction how do I parse it using regx?
function in-out (input) {var output = {}; If (input.indexOf ('Type:')! == -1) {output.types = input.replace (/. Type: ([^] +). * $ /, '$ 1'). the division ( ','); Output.keywords = input.replace (/^(.*) Type: ([^] +) (. *) $ /, '$ 1 $ 3'); } Else {output.keywords = input; } Return output; } Try it out?
Comments
Post a Comment