开发者

how to choose text from a file

i have a text file like:

"GET /opacial/index.php?op=results&catalog=1&view=1&language=el&numhits=10&query=\xce\x95\xce\xbb\xce\xbb\xce\xac\xce\xb4\xce\xb1%20--%20\xce\x95\xce\xb8\xce\xbd\xce\xb9\xce\xba\xce\xad\xcf\x82%20\xcf\x83\xcf\x87\xce\xad\xcf\x83\xce\xb5\xce\xb9\xcf\x82%20

--%20\xce\x99\xcf\x83\xcf\x84\xce\xbf\xcf\x81\xce\xaf\xce\xb1&search_field=11&page=1

And i want to cut all the 开发者_运维技巧characters after the word "query" and before "&search". (bolds above). I am trying to cut the data, using patterns but something is wrong.. Can you give me an example for the example code above?

EDIT: An other problem , except the one above is that the matcher is used only for charSequences, and i have a file, which can not casted to charSequence... :\


something like that:

   String yourNewText=yourOldText.split("query")[1].split("&search")[0];

?

to see how to read a file into a String, you can look here (there are different possiblities)


".*query\\=(.*)\\&search_field.*"

This regex should work to give you a capture of what you want to remove. Then String.replace should do the trick.

Edit - response to comment. The following code...

    String s = "GET /opacial/index.php?op=results&catalog=1&view=1&language=el&numhits=10&query=\\xce\\x95\\xce\\xbb\\xce\\xbb\\xce\\xac\\xce\\xb4\\xce\\xb1%20--%20\\xce\\x95\\xce\\xb8\\xce\\xbd\\xce\\xb9\\xce\\xba\\xce\\xad\\xcf\\x82%20\\xcf\\x83\\xcf\\x87\\xce\\xad\\xcf\\x83\\xce\\xb5\\xce\\xb9\\xcf\\x82%20 --%20\\xce\\x99\\xcf\\x83\\xcf\\x84\\xce\\xbf\\xcf\\x81\\xce\\xaf\\xce\\xb1&search_field=11&page=1";
    Pattern p = Pattern.compile(".*query\\=(.*)\\&search_field.*");
    Matcher m = p.matcher(s);
    if (m.matches()){
        String betweenQueryAndSearch = m.group(1);
        System.out.println(betweenQueryAndSearch);
    }

Produced the following output....

\xce\x95\xce\xbb\xce\xbb\xce\xac\xce\xb4\xce\xb1%20--%20\xce\x95\xce\xb8\xce\xbd\xce\xb9\xce\xba\xce\xad\xcf\x82%20\xcf\x83\xcf\x87\xce\xad\xcf\x83\xce\xb5\xce\xb9\xcf\x82%20 --%20\xce\x99\xcf\x83\xcf\x84\xce\xbf\xcf\x81\xce\xaf\xce\xb1
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜