The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> Javascript - Find string containing number then duplicate a substring by that number, Any help is greatly appreciated!
Techknowfile
post 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 smile.gif

This post has been edited by Techknowfile: May 11 2012, 12:33 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 29th March 2024 - 10:42 AM