Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在制作实时新闻自动收报机。就像推特一样,如果有任何hastagh(#blabla),那就是红色..
任何人都可以帮助我吗?提前致谢
您可能正在寻找indexOf()
indexOf() 方法返回调用 String 对象中第一次出现指定值的索引,从 fromIndex 开始搜索。如果未找到该值,则返回 -1。
同样正如其他人所评论的那样,如果您正在寻找正则表达式,那么这个也适用于您
(^|\s)(#[a-z\d][\w-]*)
演示