Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After a good while trying to help, answering to constantly changing questions, just found out that <a href="https://stackoverflow.com/questions/20627034/investigate-a-string-in-java-whether-it-is-include-some-special-signs">the same was asked yesterday</a>, and that the OP <a href="https://stackoverflow.com/users/2504767/marwief?tab=questions">doesn't accept answers to his questions</a>...all I have left to say is <em>good night sir, good luck</em></p> <p><strong>n-th answer follows:</strong></p> <p>First pattern: <code>[a-z](-[a-z])*</code> : a letter, possibly followed by more letters, separated by <code>-</code>.</p> <p>Second pattern: <code>\d+(-\d+)*[?*]*</code> : a number, possibly followed by more numbers, separated by <code>-</code>, and possibly ending with <code>?</code> or <code>*</code>.</p> <p>So join them together: <code>^([a-z](-[a-z])*)|(\d+(-\d+)*[?*]*)$</code>. <code>^</code> and <code>$</code> mark the beginning and the end of the string.</p> <p>Few more comments on the code: you don't need to use <code>Pattern.quote</code>, and you should use <code>matches()</code> instead of <code>find()</code>, because <code>find()</code> returns <code>true</code> if <em>any</em> part of the string matches the pattern, and you want <em>the whole</em> string:</p> <pre><code>public static boolean checkPatternMatching(String sourceToScan, String searchPattern) { boolean patternFounded; if (sourceToScan == null) { patternFounded = false; } else { Pattern pattern = Pattern.compile(searchPattern, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(sourceToScan); patternFounded = matcher.matches(); } return patternFounded; } </code></pre> <p>Called like this: <code>checkPatternMatching(s, "^([a-z](-[a-z])*)|(\\d+(-\\d+)*[?*]*)$")</code></p> <p>About the second question, this is the <a href="http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java?view=markup" rel="nofollow noreferrer">current implementation</a> of <code>StringUtils.isNumeric</code>:</p> <pre><code>public static boolean isNumeric(final CharSequence cs) { if (isEmpty(cs)) { return false; } final int sz = cs.length(); for (int i = 0; i &lt; sz; i++) { if (Character.isDigit(cs.charAt(i)) == false) { return false; } } return true; } </code></pre> <p>So no, there is nothing wrong about it, that is as simple as it gets. But you need to include an external JAR in your program, which I find unnecessary if you just want to use such a simple method.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload