本文整理汇总了Java中javax.annotation.RegEx类的典型用法代码示例。如果您正苦于以下问题:Java RegEx类的具体用法?Java RegEx怎么用?Java RegEx使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RegEx类属于javax.annotation包,在下文中一共展示了RegEx类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createRegexFromGlob
import javax.annotation.RegEx; //导入依赖的package包/类
/***
*
* @param glob
* @return
*/
public static final String createRegexFromGlob(final String glob) {
@RegEx
final StringBuilder re = new StringBuilder(glob.length() * 2);
re.append('^');
for (final char c : glob.toCharArray()) {
switch (c) {
case '?':
re.append('.');
// fall through
case '*':
re.append('*');
break;
default:
re.append(Pattern.quote(Character.toString(c)));
}
}
re.append('$');
return re.toString();
}
示例2: getAllMatchingGroupValues
import javax.annotation.RegEx; //导入依赖的package包/类
/**
* Get the values of all groups (RegEx <code>(...)</code>) for the passed
* value.<br>
* Note: groups starting with "?:" are non-capturing groups (e.g.
* <code>(?:a|b)</code>)
*
* @param sRegEx
* The regular expression containing the groups
* @param sValue
* The value to check
* @return <code>null</code> if the passed value does not match the regular
* expression. An empty array if the regular expression contains no
* capturing group.
*/
@Nullable
public static String [] getAllMatchingGroupValues (@Nonnull @RegEx final String sRegEx, @Nonnull final String sValue)
{
final Matcher aMatcher = getMatcher (sRegEx, sValue);
if (!aMatcher.find ())
{
// Values does not match RegEx
return null;
}
// groupCount is excluding the .group(0) match!!!
final int nGroupCount = aMatcher.groupCount ();
final String [] ret = new String [nGroupCount];
for (int i = 0; i < nGroupCount; ++i)
ret[i] = aMatcher.group (i + 1);
return ret;
}
示例3: VATINStructure
import javax.annotation.RegEx; //导入依赖的package包/类
public VATINStructure (@Nonnull final String sCountry,
@Nonnull @RegEx final String sRegEx,
@Nonnull final Collection <String> aExamples)
{
ValueEnforcer.notNull (sCountry, "Country");
ValueEnforcer.notNull (sRegEx, "RegEx");
ValueEnforcer.notEmpty (aExamples, "Example");
m_aCountry = CountryCache.getInstance ().getCountry (sCountry);
if (m_aCountry == null)
throw new IllegalArgumentException ("country");
m_sPattern = sRegEx;
m_aPattern = RegExCache.getPattern (sRegEx);
m_aExamples = new CommonsArrayList <> (aExamples);
if (GlobalDebug.isDebugMode ())
for (final String s : m_aExamples)
if (!isValid (s))
throw new IllegalArgumentException ("Example VATIN " + s + " does not match " + sRegEx);
}
示例4: AbstractPropertyAction
import javax.annotation.RegEx; //导入依赖的package包/类
/**
* Construct new action with given name and regex patterns.
*
* @param name
* name of action.
* @param strPatterns
* regex patterns to validate name of method.
*/
protected AbstractPropertyAction(String name, @RegEx String... strPatterns)
{
this.name = name;
Pattern[] patterns = new Pattern[strPatterns.length];
for (int i = 0; i < strPatterns.length; i++)
{
patterns[i] = Pattern.compile("^" + strPatterns[i] + "$");
}
this.patterns = Arrays.asList(patterns.clone());
}
示例5: getAll
import javax.annotation.RegEx; //导入依赖的package包/类
public static final List<String> getAll(String str, @RegEx String key) {
Matcher matcher = Pattern.compile(key).matcher(str);
List<String> resutlt = Lists.newLinkedList();
while (matcher.find())
resutlt.add(matcher.group(1));
return resutlt;
}
示例6: AbstractPropertyAction
import javax.annotation.RegEx; //导入依赖的package包/类
protected AbstractPropertyAction(String name, @RegEx String... strPatterns)
{
this.name = name;
Pattern[] patterns = new Pattern[strPatterns.length];
for (int i = 0; i < strPatterns.length; i++)
{
patterns[i] = Pattern.compile("^" + strPatterns[i] + "$");
}
this.patterns = List.of(patterns);
}
示例7: stringReplacePattern
import javax.annotation.RegEx; //导入依赖的package包/类
@Nonnull
public static String stringReplacePattern (@Nonnull @RegEx final String sRegEx,
@Nonnull final String sValue,
@Nullable final String sReplacement)
{
// Avoid NPE on invalid replacement parameter
return getMatcher (sRegEx, sValue).replaceAll (StringHelper.getNotNull (sReplacement));
}
示例8: isValidPattern
import javax.annotation.RegEx; //导入依赖的package包/类
/**
* Check if the passed regular expression is invalid.<br>
* Note: this method may be a performance killer, as it calls
* {@link Pattern#compile(String)} each time, which is CPU intensive and has a
* synchronization penalty.
*
* @param sRegEx
* The regular expression to validate. May not be <code>null</code>.
* @return <code>true</code> if the pattern is valid, <code>false</code>
* otherwise.
*/
public static boolean isValidPattern (@Nonnull @RegEx final String sRegEx)
{
try
{
Pattern.compile (sRegEx);
return true;
}
catch (final PatternSyntaxException ex)
{
return false;
}
}
示例9: checkPatternConsistency
import javax.annotation.RegEx; //导入依赖的package包/类
public static void checkPatternConsistency (@Nonnull @RegEx final String sRegEx) throws IllegalArgumentException
{
// Check if a '$' is escaped if no digits follow
int nIndex = 0;
while (nIndex >= 0)
{
nIndex = sRegEx.indexOf ('$', nIndex);
if (nIndex != -1)
{
if (nIndex == sRegEx.length () - 1)
{
// '$' at end of String is OK!
}
else
// Is the "$" followed by an int (would indicate a replacement group)
if (!Character.isDigit (sRegEx.charAt (nIndex + 1)))
{
if (nIndex + 1 < sRegEx.length () && sRegEx.charAt (nIndex + 1) == ')')
{
// "$" is the last char in a group "(...$)"
}
else
if (nIndex > 0 && sRegEx.charAt (nIndex - 1) == '\\')
{
// '$' is quoted
}
else
throw new IllegalArgumentException ("The passed regex '" +
sRegEx +
"' contains an unquoted '$' sign at index " +
nIndex +
"!");
}
// Move beyond the current $
nIndex++;
}
}
}
示例10: RegExPattern
import javax.annotation.RegEx; //导入依赖的package包/类
public RegExPattern (@Nonnull @Nonempty @RegEx final String sRegEx,
@Nonnegative final int nOptions) throws IllegalArgumentException
{
ValueEnforcer.notEmpty (sRegEx, "RegEx");
ValueEnforcer.isGE0 (nOptions, "Options");
m_sRegEx = sRegEx;
m_nOptions = nOptions;
if (areDebugConsistencyChecksEnabled ())
checkPatternConsistency (sRegEx);
}
示例11: getRegEx
import javax.annotation.RegEx; //导入依赖的package包/类
/**
* @return The source regular expression string. Neither <code>null</code> nor
* empty.
*/
@Nonnull
@Nonempty
@RegEx
public String getRegEx ()
{
return m_sRegEx;
}
示例12: resolveVariables
import javax.annotation.RegEx; //导入依赖的package包/类
@RegEx
private static String resolveVariables(String pattern) {
Matcher matcher = Pattern.compile("\\$\\{([\\w\\d]+)}").matcher(pattern);
StringBuffer buffer = new StringBuffer();
while (matcher.find()) {
String key = matcher.group(1);
String var = FilterAddon.getVariable(key);
matcher.appendReplacement(buffer, var);
}
matcher.appendTail(buffer);
return pattern;
}
示例13: get
import javax.annotation.RegEx; //导入依赖的package包/类
public static final String get(String str, @RegEx String key) {
Matcher matcher = Pattern.compile(key).matcher(str);
if (matcher.find())
return matcher.group(1);
return "";
}
示例14: setPattern
import javax.annotation.RegEx; //导入依赖的package包/类
public void setPattern(@RegEx String pattern) throws PatternSyntaxException {
testPatternUnsafe(pattern);
this.pattern = pattern;
this.expression = null;
}
示例15: getListOfFieldsRegExp
import javax.annotation.RegEx; //导入依赖的package包/类
/**
* Get a sub-list with all entries that have field names matching the passed
* regular expression.
*
* @param sRegExp
* The regular expression to compare the entries against.
* @return Never <code>null</code>.
*/
@Nonnull
@ReturnsMutableCopy
default IErrorList getListOfFieldsRegExp (@Nonnull @Nonempty @RegEx final String sRegExp)
{
return getSubList (x -> x.hasErrorFieldName () &&
RegExHelper.stringMatchesPattern (sRegExp, x.getErrorFieldName ()));
}