regex - regular expression in javascript, detecting optional arguments -
i'm doing replacements on tokenized strings below:
var mystring = "i replace following token <<start<arg1,arg2 >>> in string" or var mystring = "the expression has optional <<start<arg1,arg2,arg3 >>> third argument"
within token, there 2 or 3 alphanumeric strings capture , pass regex callback function:
mystring.replace(regexexpression, function(m, arg1, arg2, arg3) { return foo(arg1, arg2, arg3); });
what regex expression match both versions of mystring, capture arg1, arg2, , optional arg3?
description
try put each arg group 1 2 or 3 respectively, see regexplanet sample
- each attribute group starts
<<start<
, ends>>>
- will match between 2 , 3 groups of comma delimited substrings between open , close tags, additional groups matched inserting
(?:,([^,>]*))?
between second , third groups. - token 3 optional
<<start<([^,>]*)(?:,([^,>]*))(?:,([^>]*))?(?=>>>)
Comments
Post a Comment