All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sirolf2009.util.RegexUtil Maven / Gradle / Ivy

The newest version!
package com.sirolf2009.util;

import java.util.NoSuchElementException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@SuppressWarnings("all")
public class RegexUtil {
  public static String extract(final String string, final String pattern) {
    return RegexUtil.extract(string, Pattern.compile(pattern));
  }
  
  public static String extract(final String string, final Pattern pattern) {
    final Matcher matcher = pattern.matcher(string);
    boolean _find = matcher.find();
    if (_find) {
      return matcher.group(1);
    } else {
      String _pattern = pattern.pattern();
      String _plus = ((("The string \"" + string) + "\" does not contain the pattern \"") + _pattern);
      String _plus_1 = (_plus + "\"");
      throw new NoSuchElementException(_plus_1);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy