javascript - HTML & Regex, how to match text inbetween commas with keyword -


let have <b>location: </b> uk, england, london <br>

to select line regex im using (location:+.*?<br\/?>), doing job need return 3 elements between commas in seperate variables.

the variables in javascript, so.

var location = document.body.outerhtml.match(/(location:+.*?<br\/?>)/gi);   //returns entire line location:**is working var country = document.body.outerhtml.match(/(location:[^,]*)/gi);         //returns uk, usa etc **is working var state = document.body.outerhtml.match(/(location:???;                  //needs return 'england' etc  var city= document.body.outerhtml.match(/(location:???;                   //needs return 'london' etc 

i have got country using (location:[^,]*) returns 'uk' expected, don't know how amend return 'england' , again return 'london'.

i've seen examples of how select commas, can't find helps me specify how text after second , third commas, specific keyword of "location:".

thanks in advance

you can use this:

var tmp = document.body.outerhtml.match(     /location: <\/b> ([^,]+), ([^,]+), ([^,]+)/i );  var country = tmp[1]; var state   = tmp[2]; var city    = tmp[3]; 

updated match words spaces between commas.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -