Share

Search Java Code Snippets


  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.





#Java - Code Snippets for '#Matcher' - 9 code snippet(s) found

 Sample 1. 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 2. 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 3. Method to check if the WebUrl matches a Pattern.

public boolean shouldVisit(WebURL url) {
Pattern filters = Pattern.compile(".*(.(htm|html))$");

String href = url.getURL().toLowerCase();
if(filters.matcher(href).matches()){
return true;
}
return false;
}

   Like      Feedback     weburl  patternmatching  .getURL()  pattern  pattern.matcher  pattern.matcher.matches   regex  regular expression


 Sample 4. Get Number of instances a pattern exist in the text

public int getNoOfQuestions(){    
   Pattern p = Pattern.compile("Ans.");
Matcher m = p.matcher(text);
int count = 0;
while (m.find()){
   count = count + 1;
}
return count-3;
}

   Like      Feedback     pattern matching  Pattern  Matcher  Matcher.find


Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
 Sample 5. Code Sample / Example / Snippet of static org.hamcrest.CoreMatchers.not

  public ParameterExpression(int modifier, Type type, String name) {

super(ExpressionType.Parameter, type);

assert name != null : "name should not be null";

assert Character.isJavaIdentifierStart(name.charAt(0))

: "parameter name should be valid java identifier: "

+ name + ". The first character is invalid.";

this.modifier = modifier;

this.name = name;

}


   Like      Feedback      static org.hamcrest.CoreMatchers.not


 Sample 6. Code Sample / Example / Snippet of java.util.regex.Matcher

    private void defineVariables(String line) {

Matcher varDefn = matchesVarDefn.matcher(line);

if (varDefn.lookingAt()) {

String var = varDefn.group(1);

String val = varDefn.group(2);

vars.define(var, val);

} else {

String[] words = splitWords.split(line);

for (String var : words) {

String value = System.getenv(var);

vars.define(var, value);

}

}

}


   Like      Feedback      java.util.regex.Matcher


 Sample 7. Code Sample / Example / Snippet of org.hamcrest.Matcher

    private void defineVariables(String line) {

Matcher varDefn = matchesVarDefn.matcher(line);

if (varDefn.lookingAt()) {

String var = varDefn.group(1);

String val = varDefn.group(2);

vars.define(var, val);

} else {

String[] words = splitWords.split(line);

for (String var : words) {

String value = System.getenv(var);

vars.define(var, value);

}

}

}


   Like      Feedback      org.hamcrest.Matcher


 Sample 8. Code Sample / Example / Snippet of static org.hamcrest.CoreMatchers.is

  public static final List<Pair<String, String>> FOODMART_QUERIES =

querify(QUERIES);



@Test public void testJanino169() {

CalciteAssert.that()

.with(CalciteAssert.Config.JDBC_FOODMART)

.query(

"select "time_id" from "foodmart"."time_by_day" as "t" ")

.returnsCount(730);

}




   Like      Feedback      static org.hamcrest.CoreMatchers.is


 Sample 9. Usage of org.springframework.security.web.util.matcher.RequestMatcher

RequestMatcher matcher = new RegexRequestMatcher("(.*/(html|php|htm)/.*)", RequestMethod.GET.name());
registry.addInterceptor(new MyInterceptor(matcher));

   Like      Feedback     rg.springframework.security.web.util.matcher.RequestMatche



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus