简体   繁体   English

RegEx在Java脚本签名后匹配单词

[英]RegEx match a word after a sign Java Script

I know I'm going to be bashed for this question. 我知道我会被这个问题困扰。 I know it is basics and I know it was asked many times, but it seems I'm to dumb to understand examples and I need solution. 我知道这是基础知识,我知道它被问过很多次,但是看来我很愚蠢,无法理解示例,我需要解决方案。 My problem: 我的问题:

user is sending a string to server. 用户正在向服务器发送字符串。 It should be /nick #nick_name I want to match only nick_name, I also want to consider situation, when user is not cooperating and send something like "/nick #nick_name and some trash". 应该是/ nick #nick_name我只想匹配nick_name,我还想考虑用户不合作时发送“ / nick #nick_name和一些垃圾”之类的情况。 I don't need #, I don't need space after. 我不需要#,之后也不需要空间。 I have a permanent brain fart on this. 我对此有永久性的想法。

I know about #(.*) but this match everything after a # (hash included). 我知道#(。*),但这与#(包括哈希)之后的所有内容都匹配。 I need only one word. 我只需要一个字。 The perfect solution would be a lookbehind, to catch everything after #, but it's not working on JS. 完美的解决方案是回溯,以捕获#之后的所有内容,但不适用于JS。 I really did my homework. 我确实做了功课。

try with this i think helpful 试试这个我认为有帮助

 var str = "# /nik"; var reg = /#\\s*/; console.log(str); if (reg.test(str)) { console.log(str.replace(reg, "")); } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM