简体   繁体   English

从java中的String提取especific URL

[英]Extract especific URL from String in java

I have a String like this: 我有一个像这样的字符串:

.........e1.whatsapp.net..............>.ns1.p13.dynect..hostmaster.whatsapp.com.x:a>.......X..:.... ......... e1.whatsapp.net .............>。ns1.p13.dynect..hostmaster.whatsapp.com.x:a> ... ....X..:....

And I need to extract the first URL: 我需要提取第一个URL:

e1.whatsapp.net e1.whatsapp.net

I was trying with the solution in this post but not working for me, maybe because the amount of dots. 我与溶液中尝试这一职位 ,但不是为我工作,也许是因为点的数量。 Maybe if I try with another pattern regex, but I know nothing about "regex". 也许如果我尝试使用另一种模式正则表达式,但对“ regex”一无所知。

Any sugestion? 有什么建议吗?

This code below may help you to extract the email with using regex. 下面的代码可以帮助您使用正则表达式提取电子邮件。

class StringSeperator {

  public static void main(String args[]){
    String urlString = ".........e1.whatsapp.net..............>.ns1.p13.dynect..hostmaster.whatsapp.com.x:a>.......X..:....";
    String array[] = urlString.split("\\.\\.+"); 
    System.out.println(array[1]);
  }
}

Here I use regex as \\\\.\\\\.+ which means two or more dots. 在这里,我将正则表达式用作\\\\.\\\\.+ ,表示两个或多个点。 The string split using two or more dots. 字符串使用两个或多个点进行分割。

If I further explain about regex. 如果我进一步解释正则表达式。 Here I use \\\\. 在这里,我使用\\\\. for depicting the dot and use + for saying one or more occurrences of a dots. 用于描绘点,并使用+表示一个或多个点的出现。 For more details about Java regex please follow below link. 有关Java正则表达式的更多详细信息,请点击以下链接。

https://www.tutorialspoint.com/java/java_regular_expressions.htm https://www.tutorialspoint.com/java/java_regular_expressions.htm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM