我正在尝试使用 Dart 中的 Replaceall 正则表达式方法从 Facebook 图片 URL 中获取 id 号。在下面的代码中我应该使用什么来代替 $2 ?我需要的id号在“asid=”和“&height”之间。
void main() {
String faceavatar = 'https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=10153806530149154&height=50&width=50&ext=1596623207&hash=AeSi1yDvk8TCqZql';
String currentavatar = faceavatar.replaceAll(RegExp('(.*asid=)(\d*)height.*'), $2;
print(currentavatar);
}
Run Code Online (Sandbox Code Playgroud) 我有一个包含不同种类的html标签的字符串.
我想删除所有<a>和</a>标签.
我试过了:
string.replaceAll("<a>", "");
string.replaceAll("</a>", "");
Run Code Online (Sandbox Code Playgroud)
但它不起作用.这些标签仍保留在字符串中.为什么?
我有一个字符串
"age = 18 || name ='Mistic'|| civilstatus ='married'|| gender ='0'"
我需要替换"||" 通过"或".我试着跟随代码.
System.out.println("age = 18 || name = 'Mistic' || civilstatus = 'married' || gender = '0'".replaceAll("||", "OR"));
Run Code Online (Sandbox Code Playgroud)
但我得到了
"ORaORgOReOR OR = OR OR1OR8OR OR |和| OR ORnORaORmOReOR OR = OR OR'ORMORiORsORtORiORcOR'OR OR |和| OR ORcORiORvORiORlORsORtORaORtORuORsOR OR = OR OR'ORmORaORrORrORiOReORdOR'OR OR |和| OR ORgOReORnORdOReORrOR OR = OR OR'OR0OR'OR"
我需要的是
"年龄= 18或姓名='Mistic'或civilstatus ='已婚'或性别='0'"
我怎样才能做到这一点.
编辑我已经阅读了这个问题的问题和答案,并不是类似的.因为这个问题是关于替换字符串而我的问题是关于为我的代码获取不熟悉的结果.
我需要替换页面的整个HTML或其正文内容(而不是将更多html附加到现有内容).
接受答案在这里教我如何返回数据,但加入到"身体"不相当的工作.这是我现在拥有的jQuery:
<script>
$(document).ready(function () {
$("#btnGetData").click(function () {
document.body.style.cursor = 'wait';
$.ajax({
type: 'GET',
url: '@Url.RouteUrl(routeName : "QuadrantData", routeValues : new { httpRoute = true , unit = "ABUELOS", begdate = "2016-08-20", enddate = "2016-08-27" })',
contentType: 'text/plain',
cache: false,
xhrFields: {
withCredentials: false
},
success: function (returneddata) {
$("body").remove;
$("body").append($(returneddata));
},
error: function () {
console.log('hey, boo-boo!');
}
}); // ajax
document.body.style.cursor = 'pointer';
}); // button click
}); // ready
</script>
Run Code Online (Sandbox Code Playgroud)
...所以你可以看到我试图先删除正文中的html,然后将返回的数据附加到正文中.
这个REST方法返回我想要的html: …
我一直在研究一些Java代码,我遇到了一个非常奇怪的错误,我试图用Integer替换一段字符串.添加了各种调试但我似乎无法找到它.
private void executeMsg() {
value = value.replaceAll("(&([a-f0-9]))", "§$2");
String border = tostiuhc.getWorldManager().getBorderSize() - tostiuhc.getShrinksize() + "";
String time = tostiuhc.getPhase().getMinutes() + "";
System.out.println("BORDER: " + border);
System.out.println("TIME: " + time);
value = value.replace("-border-", border + "");
value = value.replace("-time-", time + "");
tostiuhc.broadcast(value + " " + time);
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我创建了一个名为'time'的新String,并将其打印出来'TIME:value'.我正在改变的原始字符串是:该事件现在是时间 - 分钟!


这里的问题是System.out.println("TIME:")显示正确的值,但.replace只是DOESNT工作.我无法理解这一点,任何人都有任何想法?
我们正在使用String的replaceAll方法,我们不能替换{在任何字符串中.我们的例子:
试过:
"some { string".replaceAll("{", "other string");
Run Code Online (Sandbox Code Playgroud)
错误如下:
java.util.regex.PatternSyntaxException:发生非法重复
对任何想法开放!也许有一个解决方法?!
我需要将字符串“\”替换为“/”我尝试过
myString.replace("\","/");
但这是它所说的语法
字符串文字未正确用双引号关闭
我该怎么做 ?