Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何删除字符串中特定值之前的所有文本_Javascript_Jquery_String_Line Breaks - Fatal编程技术网

Javascript 如何删除字符串中特定值之前的所有文本

Javascript 如何删除字符串中特定值之前的所有文本,javascript,jquery,string,line-breaks,Javascript,Jquery,String,Line Breaks,我有下面的字符串“blahblahhellother”,我希望使用JavaScript和/或JQuery将其缩短为“hellother” 我已尝试使用以下代码: var titletext123 = "blahblah<br>hellothere" var injuryt3xt = titletext123.substring(titletext123.indexOf("<br>") +1); var titletext123=“blahblahhell

我有下面的字符串“blahblah
hellother”,我希望使用JavaScript和/或JQuery将其缩短为“hellother”

我已尝试使用以下代码:

var titletext123 = "blahblah<br>hellothere"
        var injuryt3xt = titletext123.substring(titletext123.indexOf("<br>") +1);
var titletext123=“blahblah
hellother” var injuryt3xt=titletext123.substring(titletext123.indexOf(“
”)+1);
它只返回“br>hellother”

是否有人有任何代码可以删除
及其前面的所有文本

多谢各位。非常感谢您的帮助

成功

var titletext123 = "blahblah<br>hellothere" var injuryt3xt = titletext123.substring(titletext123.indexOf("<br>") + 4);
var titletext123=“blahblah
hellother”var injuryt3xt=titletext123.substring(titletext123.indexOf(“
”)+4);
所以是+4。它解释了

中的所有字符

var titletext123 = "blahblah<br>hellothere" var injuryt3xt = titletext123.substring(titletext123.indexOf("<br>") + 4);
var titletext123=“blahblah
hellother”var injuryt3xt=titletext123.substring(titletext123.indexOf(“
”)+4);
所以是+4。它解释了

中的所有字符,您可以使用并获取第二个元素

var titletext123=“blahblah
hellother”; var injuryt3xt=titletext123.split(“
”)[1]; 警惕(伤害3XT)您可以使用并获取第二个元素

var titletext123=“blahblah
hellother”; var injuryt3xt=titletext123.split(“
”)[1];
警惕(伤害3XT)使用正则表达式:

var text = "blahblah<br>hellothere"
var clipped = str.replace(/.+\<br\>/, ""));
var text=“blahblah
hellothere” var clipped=str.replace(/.+\/,“”);
使用正则表达式:

var text = "blahblah<br>hellothere"
var clipped = str.replace(/.+\<br\>/, ""));
var text=“blahblah
hellothere” var clipped=str.replace(/.+\/,“”);
另一个选项(取决于具体情况)可能是:

var injuryt3xt = titletext123.split("<br>")[1];
var injuryt3xt=titletext123.split(“
”)[1];
这将拆分

上的字符串,并返回一个包含剩余部分的数组。。。第二个选项与
[1]

一起引用,另一个选项(取决于具体情况)可能是:

var injuryt3xt = titletext123.split("<br>")[1];
var injuryt3xt=titletext123.split(“
”)[1];

这将拆分

上的字符串,并返回一个包含剩余部分的数组。。。第二个是用
[1]

引用的,您没有考虑中断标记的长度:
var injuryt3xt=titletext123.substring(titletext123.indexOf(“
”)+4);/*+4*/
您没有考虑中断标记的长度:
var injuryt3xt=titletext123.substring(titletext123.indexOf(“
”)+4);/*+4*/