String containing hashtag to reactjs element

Hi all I am using coffee script and ReactJS for my site. So far I have a smooth development until I encounter String with hashtag and then convert hash tag to react element

React ELEMENT

@HashtagLink = React.createClass
displayName: 'hashtag link' 
  render: ->
    React.DOM.a null,
      href:'/hashtag/' + @props.hashtag
      @props.hashtag

JS function

@hashTagToLink = (string) ->
  string.replace(/#(S*)/g,'<a href="http://emilenriquez.com">$1</a>')

Sample String : I am a string with #hashtag I want to be converted to link

Desired Output: I am a string with #hashtag I want to be converted to link

Current Output: I am a string with <a href="emilenriquez.com">#hashtag</a> I want to be converted to string


Source: regex

Leave a Reply