我想用regexp拆分一些字符串。 但我无法得到我想的结果。 我听说javascript不支持lookbehind。
val.split(/(?:([\.,?;\n])\s?)/gi)
["always on the go", "?", "if yes", ",", "slip-on this dress that comes with u-neck", ",", "long sleeves and loose fit", ".", "wear with slacks and beanie to finish the ensemble", ".", "", "
", "- u-neck", "
", "- long sleeves", "
", "- loose fit", "
", "- knee hemline", "
", "- plain print"]
我目前的结果是这样的
array[0] = "always on the go?";
array[1] = "if yes,";
...
...
...
array[n] = '↵'
array[n] = '↵'
array[n] = '- u-neck'
...
...
但我希望我的结果像这样
f1<-function(x) x/2+5
f2<-function(x) x/3-10
我该怎么做?
答案 0 :(得分:0)
试试这个正则表达式,它会保留你的,?在句末。
@Path("myName/{var}")
public String getN(@PathParam("var") String s) {
//my request has to lie here. It doesn't because it has one more resource.. I want to create sth like after /myname, Everything is to be on this method. How to do this?
//like I wanted path value to be /is/foo
}
答案 1 :(得分:0)
我能想到的唯一方法是编写自己的原型
replication level
并使用此
String.prototype.splitKeep = function(arr){
if (!(arr instanceof Array)) throw('input array please');
var value = this.toString();
for (var i = 0; i < arr.length; i++){
value = value.split(arr[i]).join(arr[i] + ":split:").trim();
}
value = value.split(":split:");
//remove all newlines with characters
for (var i = 0; i < value.length; i++){
var item = value[i];
if (item[item.length-1] === '\n' && item.length > 1){
value[i] = item.substring(0, item.length-1);
}
}
return value;
}