在java中从复杂字符串中提取特定单词/字符串
我有一个长字符串,格式与这个字符串相同,但是字符串中的消息n可能不同。所以我想知道,如何从java中的这个复杂字符串中提取这个特定的消息字符串在java中从复杂字符串中提取特定单词/字符串,java,Java,我有一个长字符串,格式与这个字符串相同,但是字符串中的消息n可能不同。所以我想知道,如何从java中的这个复杂字符串中提取这个特定的消息字符串 charset_test=%E2%82%AC%2C%C2%B4%2C%E2%82%AC%2C%C2%B4%2C%E6%B0%B4%2C%D0%94%2C%D0%84&post_form_id=71c3b72f4049d394140cedf32d39f525&fb_dtsg=AQBY3vp-&feedback_params=
charset_test=%E2%82%AC%2C%C2%B4%2C%E2%82%AC%2C%C2%B4%2C%E6%B0%B4%2C%D0%94%2C%D0%84&post_form_id=71c3b72f4049d394140cedf32d39f525&fb_dtsg=AQBY3vp-&feedback_params=%7B%22actor%22%3A%22176851262376586%22%2C%22target_fbid%22%3A%22283157315079313%22%2C%22target_profile_id%22%3A%22176851262376586%22%2C%22type_id%22%3A%227%22%2C%22source%22%3A%222%22%2C%22assoc_obj_id%22%3A%22%22%2C%22source_app_id%22%3A%220%22%2C%22extra_story_params%22%3A%7B%22photo_viewer_version%22%3A%222%22%7D%2C%22content_timestamp%22%3A%221327693760%22%2C%22check_hash%22%3A%22129f5441c4cb4266%22%7D&translate_on_load=&add_comment_text_text=I%20didn't%20got%20any%20msg%20in%20my%20mailbox%20%3A(&add_comment_text=I%20didn't%20got%20any%20msg%20in%20m%20inbox%20%3A(&comment_replace=optimistic_comment_2931473608_0&comment=1&lsd&post_form_id_source=AsyncRequest&__user=18802987&phstamp=165895111811245853
我想以下面的格式提取这个特定字符串
I didn't got any msg in my mailbox
下面是一个正则表达式解决方案:
String input = "charset_test=%E2%8...3A(&add_comment_text=I%20didn't%20got%20any"
+ "%20msg%20in%20m%20inbox%20%3A(&comment_replace=optim"
+ "istic_comment_2931473608_0&comment=1&lsd&post_form_id_source="
+ "AsyncRequest&__user=18802987&phstamp=165895111811245853";
Pattern p = Pattern.compile("add_comment_text_text=(.*?)[&$]");
Matcher m = p.matcher(input);
if (m.find()) {
String value = URLDecoder.decode(m.group(1), "UTF-8");
System.out.println(value);
}
输出:
I didn't got any msg in my mailbox :(
下面是一个正则表达式解决方案:
String input = "charset_test=%E2%8...3A(&add_comment_text=I%20didn't%20got%20any"
+ "%20msg%20in%20m%20inbox%20%3A(&comment_replace=optim"
+ "istic_comment_2931473608_0&comment=1&lsd&post_form_id_source="
+ "AsyncRequest&__user=18802987&phstamp=165895111811245853";
Pattern p = Pattern.compile("add_comment_text_text=(.*?)[&$]");
Matcher m = p.matcher(input);
if (m.find()) {
String value = URLDecoder.decode(m.group(1), "UTF-8");
System.out.println(value);
}
输出:
I didn't got any msg in my mailbox :(
格式是:someVariableLength可变Hexasciicharacters+文本+someVariableLength可变Hexasciicharacters?说明格式。OP大概在键
add\u comment\u text\u text
+1 aioobe、@Zara-没有得到?的值之后。格式是:SomeVariableLength VariableHexasciCharacters+文本+SomeVariableLength VariableHexasciCharacters?说明格式。OP可能在键add\u comment\u text\u text
+1 aioobe、@Zara-没有得到的值之后?