Problem
I’m having trouble with a regular expression.
I have a set of strings.
Example String
@param* URL url './' an absolute URL giving the base location of the image
@param* Function callback callback(indexInArray, valueOfElement) The function that will be executed on every object.
@param Function callback Null The function that will be executed when the image is clicked
@param String name 'this is a test name' the name to use when displaying the image
@param String name "this is a test name" the name to use when displaying the image
I’m splitting them on the new line to give me individual string.
var match = val.split("\n");
Each of these strings can be broken down into five values:
Variables
Example: @param Function callback Null The function that will be executed when the image is clicked
@param = required;
Function = type;
callback = name;
Null = default;
The function that will be executed when the image is clicked = description.
What I need is to break this string up into its parts taking into account all the different string possibilities, i’m having a hard time creating the regular expression that can split on all the different default and description posibilites.
I’m having a particular problems trying to get the defaultValue out when its a string in double or single quotes or when it’s in function notation.
Code
This is my current working code;
$.each(match, function(index, value) {
var part = value.split(/\s/); //TODO need a regx to split this string correctly
var required = part[0];
var type = part[1];
var name = part[2];
var defaultValue = part[3];
var description = part[4];
});
Summary
I need a single or multiple step regular expression that can break up all five examples above into the same five variables.
Edit: I apologies for not having had a go at the regular expression but i’m not sure where to start.
Try this:
I tested quickly using http://regexhero.net/tester/ but other than that I didn’t test it.