假设我有一个变量,字符串的长度不固定,有时像
var a = "xxxxxxxxhelloxxxxxxxx";
Run Code Online (Sandbox Code Playgroud)
有时喜欢
var a = "xxxxhelloxxxx";
Run Code Online (Sandbox Code Playgroud)
我不能使用"world"因为位置不一样.
如何在字符串中找到字符串"hello"并在"hello"之后插入字符串"world"?(欢迎使用JavaScript或jQuery中的方法)
谢谢
我想使用正则表达式拆分字符串,并在结果数组中包含分隔符/匹配信息.
在java中我用过:
theString.split("(?<=[!><=}{])|(?=[!><=}{])|(?<= AND )|(?= AND )|(?<= OR )|(?= OR )")
Run Code Online (Sandbox Code Playgroud)
但是,javascript不支持lookbehind ?<=
例如,我想要字符串:
"Reason={Existing problem or fault}{Bestaande probleem of vout}{Other}{Ander} and Required!=No and Results >=10 and Results <=25 and Tst>5 and Tst<80 and Info=test this or that and those and Success!=Yes"
Run Code Online (Sandbox Code Playgroud)
分开:
Reason,=,{,Existing problem, or ,fault,},{,Bestaande probleem of vout,},{,Other,},{,Ander,}, and ,Required,!,=,No, and ,Results,>,=,10, and ,Results,<,=,25, and ,Tst,>,5, and ,Tst,<,80, and ,Info,=,test this, or ,that, and ,those, and ,Success,!,=,Yes
Run Code Online (Sandbox Code Playgroud)
我得到的例子:
var thestr = "Reason={Existing problem or fault}{Bestaande probleem of vout}{Other}{Ander} …Run Code Online (Sandbox Code Playgroud) 我想分割一个看起来像这样的字符串:word1; word2; word3,word4,word5,word6.word7.等等
该字符串来自我从php页面获取的输出,该页面从数据库收集数据,因此字符串可能看起来不同,但第一个单词总是以; 然后,最后的话用.(点)
我希望能够获取以例如结尾的所有单词; , 要么 .成阵列.有人知道怎么做吗?
我也想知道如何只获取以...结尾的单词;
下面的函数ends_with(字符串,字符)有效,但它不考虑空格.例如,如果单词是Jonas Sand,它只打印Sand.有谁知道如何解决这个问题?