RegExps
Jan 24, 2006I'm trying to get a regExp to stop at the end of a css declaration in
the example below. I've tried many variations with no success. What I need
it to return is just the first element like this:
#myElement1 { display: block; width: 100%; padding: 5px 0 5px 10px; }
But it grabs both instead like this:
#myElement1 { display: block; width: 100%; padding: 5px 0 5px 10px; }
#myElement2 { display: block; width: 100%; padding: 5px 0 5px 10px; }
Does anyone know how to make it stop at the closing bracket of the first
style? Here is one example of the code I have tried.
<script type="text/javascript">
function alertReg(){
var element=document.getElementById("myDiv").innerHTML;
var pattern= /#myElement {[^$]*}/;
var patternMatch= element.match(pattern);
if(patternMatch){
alert(patternMatch);
}
}
</script>
In the HTML I have this div.
<div id="myDiv">
#myElement1 { display: block; width: 100%; padding: 5px 0 5px 10px; }
#myElement2 { display: block; width: 100%; padding: 5px 0 5px 10px; }
</div>
Any suggestions welcome.
David B.