javascript - regedx working on a gloabl scale where 2 or more results shoud return -
i trying find results (could more 1) , process these, having issues /g. doesnt seem want return multiple results
i have following code
<div id="test"> <p> <!--{byond:cta|localaction:contact|contact us}--><\/p> <p> <\/p> <p> <sub><strong>important information:<\/strong> offer available new home loans. *comparison rate calculated on loan amount of $150,000 on term of 25 years. **minimum redraw of $500. ^limits apply fixed rate home loans.<\/sub><\/p> <!--{byond:cta|localaction:product:45|product}--> </div>
i trying each instance of byond local action amd split string
i using
var introduction = $("#test").html(); var initexpr = /<!--{byond\:cta\|localaction[^}]+}-->/gm; var initresult = initexpr.exec(introduction); // result 1... why? var length = initresult.length; //based on length split results (var = 0; < length; i++) { var expr = /(?:<!--{byond\:cta\|)(.*)\|(.*)(?:}-->)/i; var result = expr.exec(introduction); console.log(result[0], "string"); console.log(result[1], "local action"); console.log(result[2], "button name"); }
i ever length of 1 first result.. should 2.. , need use work out splitting individual result
can help
to matches, must put exec() method in while loop.
you can have result looking this:
<script type="text/javascript"> var subject = document.getelementbyid('test').innerhtml; var pattern = /<!--\{byond:cta\|([^|]+)\|([^|}]+)\}-->/g; var result = new array(); while( (match = pattern.exec(subject)) != null ) { result.push(match); } </script>
you obtain:
[["<!--{byond:cta|localaction:contact|contact us}-->", "localaction:contact", "contact us"], ["<!--{byond:cta|localaction:product:45|product}-->", "localaction:product:45", "product"]]
Comments
Post a Comment