Grab strings before and after inner string in regex Javascript -
i have string this:
20 equals 'value goes here'
i want split 3 separate strings:
conditionfield = 20
conditionoperation = 'equals'
conditionvalue = 'value goes here'
i tried condition field:
var conditionfield = condition.replace(/(.*)(.*equals)/, '$1');
but get's beginning , end.
i'm having trouble splitting , dealing white space , spaces in value.
your question bit of challenge if wanted arbitrarily extract quoted terms along individual words. since appear have rather fixed structure, starting single number, single word command, followed third term, can use following regex pattern here:
([^\\s]*)\\s+([^\\s]*)\\s+(.*)
each term in parentheses above made available capture group after match has been run. in case, blanket after first 2 terms together.
var string = "20 equals 'value goes here'"; var re = new regexp("([^\\s]*)\\s+([^\\s]*)\\s+(.*)"); match = re.exec(string); if (match != null) { console.log(match[1]) console.log(match[2]) console.log(match[3]) }
Comments
Post a Comment