#Java - Code Snippets for '#Java.util.regex.Pattern' - 3 code snippet(s) found |
|
Sample 1. Code to find email ids in a string using Pattern. | |
|
String text="vivek boy goy vivek@tech.com viv@ek.com sdjs@adjk";
Pattern regex = Pattern.compile("[@]");
Matcher regexMatcher = regex.matcher(text);
int i =0;
int width = 0;
while (regexMatcher.find()) {
if((regexMatcher.start()-10 > 0) && (regexMatcher.end()+10 < text.length())){
width=10;
String[] substr=text.substring(regexMatcher.start()-width,regexMatcher.end()+width).split(" ");
for(int j=0;j<substr.length;j++){
if(substr[j].contains("@") && (substr[j].contains(".com") || substr[j].contains(".net"))){
System.out.println(substr[j]);
}
}
} else {
width=0;
}
}
|
|
Like Feedback regex pattern string regexMatcher.find java.util.regex.Matcher java.util.regex.Pattern |
|
|
Sample 2. Java Code to get all images url from html code. | |
|
regex = Pattern.compile("[http]");
regexMatcher = regex.matcher(htmlParseData.getHtml());
List tr=htmlParseData.getOutgoingUrls();
imgUrlCounter=0;
for(i=0;i<tr.size();i++){
if(tr.get(i).toString().contains(".jpg") || tr.get(i).toString().contains(".jpeg") || tr.get(i).toString().contains(".gif") || tr.get(i).toString().contains(".bmp")){
url = new URL(tr.get(i).toString());
Image image = new ImageIcon(url).getImage();
}
}
|
|
Like Feedback regex pattern regex.matcher html java.util.regex.pattern regular expressions |
|
|
Sample 3. Code Sample / Example / Snippet of java.util.regex.Pattern | |
|
private long getStoreId(File storeFile) {
Pattern p = Pattern.compile(m_name + "-(\d+)");
Matcher m = p.matcher(storeFile.getName());
if (m.find()) {
return Long.parseLong(m.group(1));
}
throw new RuntimeException("Invalid store file name: " + storeFile.getName());
}
|
|
Like Feedback java.util.regex.Pattern |
|
|