Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you're doing this type of character interrogation often in a loop, you may not want to use a regexp at all but craft your own search routine interrogating a StringBuffer.</p> <pre><code>/** * Method to evaluate a String to see whether it contains one (or potentially more) of a * char or member of a group of chars. * * @param String to evaluate * * @param String containing all characters to evaluate against the subject string * * @return true on first correct match, false if no match found **/ public boolean sbContainsOneOf(String sStringToCheck, String sCheck) { StringBuffer sb = new StringBuffer(sStringToCheck); char[] tmp2 = sCheck.toCharArray(); for (int i = 0; i &lt; sb.length(); i++) { for (int k = 0; k &lt; tmp2.length; k++) if (sb.charAt(i) == tmp2[k]) { return true; } } return false; } </code></pre> <p>Then all you need to do is call it:</p> <pre><code>String password = "s8bgBQYPmUaNjkToXCJLAwAA"; System.out.println(sbContainsOneOf(password,"0123456789")); </code></pre> <p>It's between 10 and 15 times faster doing it this way.... The longer your String &amp; option list the bigger the difference between the two becomes. Generally I avoid regexps unless they're one offs or spectacularly complex to implement as code and prefer to rep them with optimised StringBuffer-based routines. Doing it this way, gradually your collection of regexp replacements fills up and you end up with a very useable way of pattern interrogation without the high associated regexp overheads.</p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    1. This table or related slice is empty.
    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