Javascript - Find string containing number then duplicate a substring by that number, Any help is greatly appreciated! |
Javascript - Find string containing number then duplicate a substring by that number, Any help is greatly appreciated! |
Techknowfile |
May 11 2012, 12:25 PM
Post
#1
|
Group: Members Posts: 4 Joined: 5-February 12 Member No.: 16,405 |
I am trying to help force an elementary search engine (which ranks its results solely by the amount of instances the searched term is found in each html page) into allowing me to influence the search results with keywords. The keywords are included in the body of the html, and are each in a paragraph with a keywords class applied. The keywords are then hidden using css.
css CODE //Hide any text with class="example" from display .example{ display: none; } HTML Excerpt CODE <p class="example">red, green[25], blue</p> I would like to use javascript to find each string in an example class paragraph that contains a number inside of brackets at the end (eg green[25]) and replace that string with the substring found before the opening bracket printed the amount of times as the number inside of the bracket, which adding a space to the start and comma to the end of each duplicate. for example, the HTML Excerpt above would be changed to: CODE <p class="example">red, green, green, green, green, green, green, green, green, green, green, green, green, green, green, green, green, green, green, green, green, green, green, green, green, green, blue</p> I do have some experience with regular expressions in SED, which I believe may help with this matter. I've simply never used regex in javascript before -_-; Can anyone point me in the right direction as to how this can be accomplished? I appreciate any help you can prove This post has been edited by Techknowfile: May 11 2012, 12:33 PM |
Lo-Fi Version | Time is now: 29th March 2024 - 10:42 AM |