admin管理员组文章数量:1313615
In the string
somethingcryptic12A@#$~` abc def@#
, I would like to replace the first word by new so that it would then be new
new abc def@#
. How can I do this using regular expression. I have made the first word cryptic to indicate that it can contain any character and any number of characters. It's the first word if there is a space after it.
In the string
somethingcryptic12A@#$~` abc def@#
, I would like to replace the first word by new so that it would then be new
new abc def@#
. How can I do this using regular expression. I have made the first word cryptic to indicate that it can contain any character and any number of characters. It's the first word if there is a space after it.
Share Improve this question asked Feb 1, 2013 at 19:22 dreamerkumardreamerkumar 1,5501 gold badge18 silver badges28 bronze badges 1- In my defense, I was able to e up with the full solution after some initial help from Some1. I had tried some solutions like [a-zA-Z] but that wouldn't work for all scenarios. – dreamerkumar Commented Feb 1, 2013 at 19:29
1 Answer
Reset to default 9You can use this regular expression
^\S+
^
represents start of the string
\S
matches any character except space..
+
matches preceding character 1 to many times
本文标签: regexreplace the first word of a javascript string using regular expressionStack Overflow
版权声明:本文标题:regex - replace the first word of a javascript string using regular expression - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741932327a2405645.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论