0

I'm working on JavaScript Regex, and I want to change the colors of the words,

Socket:, Database:, Scrapper: only.

How can I achieve this using JavaScript Regex ?

This is my Text:

Socket : Sockets Connection Made on ID : dBGWu_Y4nSI40QEPAAAB
Database : Connected to MYSQL Database Successfully...
Scrapper : Scrapper Initiated, Please wait while we load the URL...
Scrapper : The Page ""+MAIN_URL+"" loaded Successfully !
Scrapper : The Page SNAPSHOP has been taken !
Scrapper : Total jobs Found on this site : 1093 and Total Pages : 110
Scrapper : The Page Current Jobs are evaluating ...
Scrapper : Next Page Click, Please wait ...
Scrapper : Next Page is Loaded, and SNAPSHOT has been taken !
Scrapper : The Page Current Jobs are evaluating ...
Scrapper : Next Page Click, Please wait ...
Scrapper : Next Page is Loaded, and SNAPSHOT has been taken !
Scrapper : The Page Current Jobs are evaluating ...
Scrapper : Next Page Click, Please wait ...
Scrapper : Next Page is Loaded, and SNAPSHOT has been taken !
Scrapper : --------------------------------ALL PAGES ARE SCRAPPED SUCCESSFULLY---------------------------

It's basically the ul > li elements, in which I want to change the colors of some words.

I tried this :

$(".log-container").text().match(/(scrapper :)/gi)[0].css({color:"orange"});

But didn't work for me

SamWhan
  • 8,038
  • 1
  • 14
  • 42
Nadeem Ahmad
  • 505
  • 2
  • 5
  • 25

1 Answers1

0

Is this what you mean:

Replace

(Socket|Database|Scrapper)(\s*:)

with

<span style="color:blue">$1</span>$2

will wrap the words in a span setting color to blue.

text = document.body.innerHTML.replace(/(Socket|Database|Scrapper)(\s*:)/gi, '<span style="color:blue">$1</span>$2');
  
console.log( text );
document.body.innerHTML = text;
Socket : Sockets Connection Made on ID : dBGWu_Y4nSI40QEPAAAB<br/>
Database : Connected to MYSQL Database Successfully...<br/>
Scrapper : Scrapper Initiated, Please wait while we load the URL...<br/>
Scrapper : The Page ""+MAIN_URL+"" loaded Successfully !<br/>
Scrapper : The Page SNAPSHOP has been taken !<br/>
Scrapper : Total jobs Found on this site : 1093 and Total Pages : 110<br/>
Scrapper : The Page Current Jobs are evaluating ...<br/>
Scrapper : Next Page Click, Please wait ...<br/>
Scrapper : Next Page is Loaded, and SNAPSHOT has been taken !<br/>
Scrapper : The Page Current Jobs are evaluating ...<br/>
Scrapper : Next Page Click, Please wait ...<br/>
Scrapper : Next Page is Loaded, and SNAPSHOT has been taken !<br/>
Scrapper : The Page Current Jobs are evaluating ...<br/>
Scrapper : Next Page Click, Please wait ...<br/>
Scrapper : Next Page is Loaded, and SNAPSHOT has been taken !<br/>
Scrapper : --------------------------------ALL PAGES ARE SCRAPPED SUCCESSFULLY---------------------------<br/>
SamWhan
  • 8,038
  • 1
  • 14
  • 42