title: How to retrieve string after @ character and before space using javascript or react?
body: <p>I'm new to programming. I would like to retrieve the string after an <code>@</code> character and before the next <kbd>space</kbd> entered by a user in an input field. For example take something like this:</p>
  
  <blockquote>
    <p>somestring @user enters</p>
  </blockquote>
  
  <p>I would like to extract the string "user" here.</p>
  
  <p>I have an input field and user entered input is stored in text state. Then whenever user enters @ in the input field i want to display a dropdown with the list of users. Now, when the user enters anything after the @ character I want to filter the users based on that string.</p>
  
  <p>Currently this text state contains the entire user input.</p>
  
  <p>Now when I filter the users list based on the text state it returns an empty array, because I'm filtering on the entire string.</p>
  
  <p>Below is the code I have written to try and solve the problem:</p>
  
  <pre><code>class UserMention extends react.PureComponent {
      state = {
          text='',
          user_mention=false,
      };
  
      user_list = [
          {name: 'user1'},
          {name: 'first_user'},
          {name: 'second_user'},
      ];
  
      handle_input_change = (event) =&gt; {
          let user_mention;
          if (event.target.value.endsWith('@')) {
              user_mention = true;
          } else {
              user_mention = false;
          }
  
          this.setState({
              is_user_mention: is_user_mention,
              [event.target.name]: event.target.value,
          });
       }  
  
       render = () =&gt; {
           return {
               &lt;input
                    required
                    name="text"
                    value={this.state.text}
                    onChange={this.handle_input_change}
                    type="text"/&gt;
                {this.state.user_mention &amp;&amp;
                    &lt;div&gt;
                        {this.user_list.filter(user =&gt; 
                            user.user_name.indexOf(this.state.new_comment) 
                            !== -1).map((user,index) =&gt; (
                                &lt;div key={index}&gt;{user.name}
                                &lt;/div&gt;
                            )) 
                         }
                     &lt;/div&gt;
                 }
             );};}
  </code></pre>