I have a string in the following format:
ignorethis_capture1_capture2_[more captured groups]
The string to be matched is delimited by '_'
. I need to get all the matched strings separately except the 'ignorethis'
string which is always at the beginning. I can delimit by '_'
but then have a problem with getting the last captured group.
eg string: start_data1_data2_data3
should give: data1 , data2 , data3 as matched groups
Thanks in advance
UPDATE: I know this can be done using string split. I was just befuddled as to how to do such an operation using regex so thought to ask here
You don't need regex:
var s = 'start_data1_data2_data3'; alert(s.split('_').slice(1));
Please try:
var s = 'start_data1_data2_data3'; re = /_([^_]+)/g; result = []; while (m = re.exec(s)) { result.push(m[1]); } document.write(result.join(','));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.