Searching for values in string, then updating the string - Javascript String

Javascript examples for String:replace

Description

Searching for values in string, then updating the string

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <script type="text/javascript">
String.prototype.addLink = function(){
    return this.replace(/(@(\w+))/g,'<a href="http://java2s.com/?q=$2">$1</a>');
};
document.write('some @test here'.addLink());

      </script>  
   </body>//from ww w . j  a v  a2s.  co  m
</html>

Related Tutorials