V
VUNETdotUS
Hi, I am working with this regexp to extract address: city, state, and
zip. This version kinda works but it extracts one element of an array
instead of three and keeps my "city" too long, including all text
before it.
.....................
var regex = /\s*(.*)\s*,\s*([A-Z]{2})\s+(\d{5}(\-\d{4})?)\s*/g;
function doit(){
var arr = d.innerHTML.match(regex);
if(arr.length=3){
d2.innerHTML = arr[0]+" | "+arr[1]+" | "+arr[2];
}else{
d2.innerHTML = "Found "+arr.length+" matches";
}
}
//-->
</script>
.......................
<div id="myDiv">
Some text here, not always break after <br>New Haven, CT 06460 plus
whatever text here too
</div>
Thanks.
zip. This version kinda works but it extracts one element of an array
instead of three and keeps my "city" too long, including all text
before it.
.....................
var regex = /\s*(.*)\s*,\s*([A-Z]{2})\s+(\d{5}(\-\d{4})?)\s*/g;
function doit(){
var arr = d.innerHTML.match(regex);
if(arr.length=3){
d2.innerHTML = arr[0]+" | "+arr[1]+" | "+arr[2];
}else{
d2.innerHTML = "Found "+arr.length+" matches";
}
}
//-->
</script>
.......................
<div id="myDiv">
Some text here, not always break after <br>New Haven, CT 06460 plus
whatever text here too
</div>
Thanks.