I have a string for example: "GamerTag":"A Talented Boy","GamerTileUrl"
and what I have been trying and failing to get is the value: A Talented Boy
. I need help creating a regex string to get specifically just A Talented Boy
. Can somebody please help me!
我有一个字符串例如:“GamerTag”:“一个有才华的男孩”,“GamerTileUrl”以及我一直在尝试和未能得到的是价值:一个有才华的男孩。我需要帮助创建一个正则表达式字符串,以获得一个特别有才华的男孩。有人能帮帮我吗!
5 个解决方案
#1
0
var str = "\"GamerTag\":\"A Talented Boy\",\"GamerTileUrl\"";
var colonParts = str.Split(':');
if (colonParts.Length >= 2) {
var commaParts = colonParts[1].Split(',');
var aTalentedBoy = commaParts[0];
var gamerTileUrl = commaParts[1];
}
This allows you to also get other parts of the comma-separated list.
这允许您还获取逗号分隔列表的其他部分。
#2
0
Suppose s is your string (no check here):
假设s是你的字符串(这里没有检查):
s = s.Split(':')[1].Split(',')[0].Trim('"');
If you want to have a Regex
solution, here it is:
如果您想要一个Regex解决方案,这里是:
s = "\"GamerTag\":\"A Talented Boy\",\"GamerTileUrl\"";
Regex reg = new Regex("(?<=:\").+?(?=\")");
s = reg.Match(s).Value;
#3
0
You can use string methods:
您可以使用字符串方法:
string result = text.Split(':').Last().Split(',').First().Trim('"');
The First/Last
extension methods prevent exceptions when the separators are missing.
第一个/最后一个扩展方法可防止分隔符丢失时出现异常。
#4
0
I think it's safe to assume that your string is actually bigger than what you showed us and it contains multiple key/value pairs? I think this is will do what you are looking for:
我认为可以安全地假设你的字符串实际上比你给我们的字符串更大并且它包含多个键/值对?我想这会做你想要的:
str.Split("GamerTag:\"")[1].Split("\"")[1];
The first split targets "GamerTag:"
and gets everything after it. The second split gets everything between first and second "
that exists in that chunk after "GamerTag:"
第一次拆分的目标是“GamerTag:”并获取其后的所有内容。第二个分裂得到第一个和第二个之间的所有东西“在GamerTag之后存在于那个块中:”
#5
0
How about this?
这个怎么样?
\:\"([^\"]+)\"
This matches the semicolon and the opening quote, and matches any non-quote characters until the next quote.
这与分号和开头引号匹配,并匹配任何非引号字符,直到下一个引号。
#1
0
var str = "\"GamerTag\":\"A Talented Boy\",\"GamerTileUrl\"";
var colonParts = str.Split(':');
if (colonParts.Length >= 2) {
var commaParts = colonParts[1].Split(',');
var aTalentedBoy = commaParts[0];
var gamerTileUrl = commaParts[1];
}
This allows you to also get other parts of the comma-separated list.
这允许您还获取逗号分隔列表的其他部分。
#2
0
Suppose s is your string (no check here):
假设s是你的字符串(这里没有检查):
s = s.Split(':')[1].Split(',')[0].Trim('"');
If you want to have a Regex
solution, here it is:
如果您想要一个Regex解决方案,这里是:
s = "\"GamerTag\":\"A Talented Boy\",\"GamerTileUrl\"";
Regex reg = new Regex("(?<=:\").+?(?=\")");
s = reg.Match(s).Value;
#3
0
You can use string methods:
您可以使用字符串方法:
string result = text.Split(':').Last().Split(',').First().Trim('"');
The First/Last
extension methods prevent exceptions when the separators are missing.
第一个/最后一个扩展方法可防止分隔符丢失时出现异常。
#4
0
I think it's safe to assume that your string is actually bigger than what you showed us and it contains multiple key/value pairs? I think this is will do what you are looking for:
我认为可以安全地假设你的字符串实际上比你给我们的字符串更大并且它包含多个键/值对?我想这会做你想要的:
str.Split("GamerTag:\"")[1].Split("\"")[1];
The first split targets "GamerTag:"
and gets everything after it. The second split gets everything between first and second "
that exists in that chunk after "GamerTag:"
第一次拆分的目标是“GamerTag:”并获取其后的所有内容。第二个分裂得到第一个和第二个之间的所有东西“在GamerTag之后存在于那个块中:”
#5
0
How about this?
这个怎么样?
\:\"([^\"]+)\"
This matches the semicolon and the opening quote, and matches any non-quote characters until the next quote.
这与分号和开头引号匹配,并匹配任何非引号字符,直到下一个引号。