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.
如何使用javascript替换方法替换某个单词之后的所有字符。
例如:“这是示例文本。”
当任何一行包含“sample”时,从单词“sample”到行尾应替换为“ * ”。该行应该是
“是* ”
我知道我必须使用正则表达式,但我不知道应该是什么?
使用可以使用这个
<div id="something">this is sample value</div> var value=$('div:contains("sample")').text(); var newvalue=value.substr(0,value.search( 'sample' ))