List of usage examples for java.util.regex Pattern CASE_INSENSITIVE
int CASE_INSENSITIVE
To view the source code for java.util.regex Pattern CASE_INSENSITIVE.
Click Source Link
From source file:nya.miku.wishmaster.ui.settings.AutohideActivity.java
@SuppressLint("InflateParams") @Override/*from w ww .ja v a 2 s.c o m*/ protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); Object item = l.getItemAtPosition(position); final int changeId; if (item instanceof AutohideRule) { changeId = position - 1; } else { changeId = -1; //-1 - ? } Context dialogContext = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ? new ContextThemeWrapper(this, R.style.Neutron_Medium) : this; View dialogView = LayoutInflater.from(dialogContext).inflate(R.layout.dialog_autohide_rule, null); final EditText regexEditText = (EditText) dialogView.findViewById(R.id.dialog_autohide_regex); final Spinner chanSpinner = (Spinner) dialogView.findViewById(R.id.dialog_autohide_chan_spinner); final EditText boardEditText = (EditText) dialogView.findViewById(R.id.dialog_autohide_boardname); final EditText threadEditText = (EditText) dialogView.findViewById(R.id.dialog_autohide_threadnum); final CheckBox inCommentCheckBox = (CheckBox) dialogView.findViewById(R.id.dialog_autohide_in_comment); final CheckBox inSubjectCheckBox = (CheckBox) dialogView.findViewById(R.id.dialog_autohide_in_subject); final CheckBox inNameCheckBox = (CheckBox) dialogView.findViewById(R.id.dialog_autohide_in_name); chanSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, chans)); if (changeId != -1) { AutohideRule rule = (AutohideRule) item; regexEditText.setText(rule.regex); int chanPosition = chans.indexOf(rule.chanName); chanSpinner.setSelection(chanPosition != -1 ? chanPosition : 0); boardEditText.setText(rule.boardName); threadEditText.setText(rule.threadNumber); inCommentCheckBox.setChecked(rule.inComment); inSubjectCheckBox.setChecked(rule.inSubject); inNameCheckBox.setChecked(rule.inName); } else { chanSpinner.setSelection(0); } DialogInterface.OnClickListener save = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String regex = regexEditText.getText().toString(); if (regex.length() == 0) { Toast.makeText(AutohideActivity.this, R.string.autohide_error_empty_regex, Toast.LENGTH_LONG) .show(); return; } try { Pattern.compile(regex, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.DOTALL); } catch (Exception e) { CharSequence message = null; if (e instanceof PatternSyntaxException) { String eMessage = e.getMessage(); if (!TextUtils.isEmpty(eMessage)) { SpannableStringBuilder a = new SpannableStringBuilder( getString(R.string.autohide_error_incorrect_regex)); a.append('\n'); int startlen = a.length(); a.append(eMessage); a.setSpan(new TypefaceSpan("monospace"), startlen, a.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); message = a; } } if (message == null) message = getString(R.string.error_unknown); Toast.makeText(AutohideActivity.this, message, Toast.LENGTH_LONG).show(); return; } AutohideRule rule = new AutohideRule(); int spinnerSelectedPosition = chanSpinner.getSelectedItemPosition(); rule.regex = regex; rule.chanName = spinnerSelectedPosition > 0 ? chans.get(spinnerSelectedPosition) : ""; // 0 ? = ? rule.boardName = boardEditText.getText().toString(); rule.threadNumber = threadEditText.getText().toString(); rule.inComment = inCommentCheckBox.isChecked(); rule.inSubject = inSubjectCheckBox.isChecked(); rule.inName = inNameCheckBox.isChecked(); if (!rule.inComment && !rule.inSubject && !rule.inName) { Toast.makeText(AutohideActivity.this, R.string.autohide_error_no_condition, Toast.LENGTH_LONG) .show(); return; } if (changeId == -1) { rulesJson.put(rule.toJson()); } else { rulesJson.put(changeId, rule.toJson()); } rulesChanged(); } }; AlertDialog dialog = new AlertDialog.Builder(this).setView(dialogView) .setTitle(changeId == -1 ? R.string.autohide_add_rule_title : R.string.autohide_edit_rule_title) .setPositiveButton(R.string.autohide_save_button, save) .setNegativeButton(android.R.string.cancel, null).create(); dialog.setCanceledOnTouchOutside(false); dialog.show(); }
From source file:com.redhat.rhn.domain.channel.NewChannelHelper.java
/** * Verifies a potential label for a channel * @param label the label of the channel * @return true if it is correct, false otherwise *//*from w w w .j a v a2s .com*/ public static boolean verifyLabel(String label) { if (label.length() < 6) { return false; } Pattern pattern = Pattern.compile("^(rhn|red\\s*hat).*", Pattern.CASE_INSENSITIVE); Matcher match = pattern.matcher(label); if (match.matches()) { return false; } pattern = Pattern.compile("^[a-z\\d][a-z\\d\\-\\.\\_]*$", Pattern.CASE_INSENSITIVE); match = pattern.matcher(label); if (!match.matches()) { return false; } return true; }
From source file:controllers.Common.java
/** * Extremely low priority exception handler that will automatically * flashException and redirect for action methods decorated with a * FlashException annotation. Rethrow if the annotation is * absent.// w w w . j a v a 2s . c om */ @Catch(value = Exception.class, priority = Integer.MAX_VALUE) public static void flashExceptionHandler(Exception e) throws Exception { FlashException handler = getActionAnnotation(FlashException.class); if (handler != null) { flashException(e); if (handler.keep()) { params.flash(); Validation.keep(); } String action = handler.value(); String[] referrer = handler.referrer(); if (!action.isEmpty()) { if (!action.contains(".")) { action = getControllerClass().getName() + "." + action; } redirect(action); } else if (referrer != null && referrer.length > 0) { Http.Header headerReferrer = request.headers.get("referer"); if (headerReferrer != null && StringUtils.isNotBlank(headerReferrer.value())) { Pattern p = Pattern.compile(StringUtils.join(referrer, "|"), Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(headerReferrer.value()); if (m.find()) { redirectToReferrer(); } else { Logger.error(String.format( "The redirect page is not valid base on the FlashException referrer restriction: %s", referrer.toString())); } } else { Logger.error("Unable to redirect. No referrer available in request header"); } } else { redirectToReferrer(); } } }
From source file:de.codesourcery.jasm16.emulator.Breakpoint.java
private String substitutePlaceholders(final IEmulator emulator, String condition) { final String[] registers = new String[] { "pc", "ex", "sp", "a", "b", "c", "x", "y", "z", "i", "j" }; String registerExpression = ""; for (int i = 0; i < registers.length; i++) { final String reg = registers[i]; registerExpression += reg;//from w ww .j a va2 s . c o m if ((i + 1) < registers.length) { registerExpression += "|"; } } final Pattern registerIndirectRegEx = Pattern.compile("\\[(" + registerExpression + ")\\]", Pattern.CASE_INSENSITIVE); final Pattern registerImmediateRegEx = Pattern.compile("(" + registerExpression + ")", Pattern.CASE_INSENSITIVE); final Pattern memoryIndirectRegEx = Pattern.compile("(\\[[ ]*(0x[0-9a-f]+)[ ]*\\])"); final Pattern hexPattern = Pattern.compile("(0x[a-f0-9]+)", Pattern.CASE_INSENSITIVE); final StringBuilder result = new StringBuilder(condition); // first, replace all memory references with the memory's value // at the specified address final IPatternReplacer replacer1 = new IPatternReplacer() { @Override public String replace(Matcher matcher, String context) { final String hexString = matcher.group(2); final int address = (int) Misc.parseHexString(hexString); @SuppressWarnings("deprecation") final int decValue = emulator.getMemory().read(address); return context.replaceAll(Pattern.quote(matcher.group(1)), Integer.toString(decValue)); } }; substitutePatterns(result, memoryIndirectRegEx, replacer1); // second, substitute all hexadecimal values (0x1234) with their // decimal counterparse so we don't accidently replace a,b,c with their // register values final IPatternReplacer replacer2 = new IPatternReplacer() { @Override public String replace(Matcher matcher, String context) { final String hexString = matcher.group(1); final long decValue = Misc.parseHexString(hexString); return context.replaceAll(Pattern.quote(hexString), Long.toString(decValue)); } }; substitutePatterns(result, hexPattern, replacer2); // third, replace all register indirect [ <REG> ] expressions with their respective // memory value final IPatternReplacer replacer3 = new IPatternReplacer() { @Override public String replace(Matcher matcher, String context) { final String register = matcher.group(1); final Register reg = Register.fromString(register); final int registerValue = emulator.getCPU().getRegisterValue(reg); @SuppressWarnings("deprecation") final int memoryValue = emulator.getMemory().read(registerValue); final String toReplace = Pattern.quote("[" + register + "]"); return context.replaceAll(toReplace, Integer.toString(memoryValue)); } }; substitutePatterns(result, registerIndirectRegEx, replacer3); // fourth , replace all register immediate values with their respective // register values final IPatternReplacer replacer4 = new IPatternReplacer() { @Override public String replace(Matcher matcher, String context) { final String register = matcher.group(1); final Register reg = Register.fromString(register); final int decValue = emulator.getCPU().getRegisterValue(reg); final String toReplace = Pattern.quote(register); return context.replaceAll(toReplace, Integer.toString(decValue)); } }; substitutePatterns(result, registerImmediateRegEx, replacer4); return result.toString(); }
From source file:TelnetTest.java
public void testFTP_Telnet_Remote_Execution_003() throws IOException { os.write("testexecute\r\n".getBytes()); os.flush();/*from w w w.java2 s . co m*/ //this shell will lock, open another one and kill TEF TelnetClient tc = new TelnetClient(); tc.connect(telnetClient.getRemoteAddress()); InputStream is2 = tc.getInputStream(); OutputStream os2 = tc.getOutputStream(); readUntil(is2, prompt); os2.write("ps | grep TestExecute\r\n".getBytes()); os2.flush(); String s = readUntil(is2, prompt); Pattern p = Pattern.compile(".*\\D+(\\d+)\\s[\\s:\\d]+TestExecute Script Engine.*", Pattern.DOTALL | Pattern.CASE_INSENSITIVE); //Pattern.DOTALL => '.' includes end of line Matcher m = p.matcher(s); assertTrue(m.matches()); String s1 = m.group(1); int pid = Integer.parseInt(s1); os2.write(("kill " + pid + "\r\n").getBytes()); os2.flush(); readUntil(is2, prompt); os2.write("bye\r\n".getBytes()); os2.flush(); //we should be able now to close the other shell readUntil(is, prompt); }
From source file:com.g3net.tool.StringUtils.java
/** * ?????/*from ww w . j a v a2s .com*/ * @param src ?? * @param regex ??? * @param ignoreCase ?? * @param endPos src??(regex)??1 * @return */ public static boolean startsWith(String src, String regex, boolean ignoreCase, TInteger endPos) { Pattern p = null; if (ignoreCase) { p = Pattern.compile("^" + regex, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); } else { p = Pattern.compile("^" + regex, Pattern.MULTILINE); } Matcher m = p.matcher(src); while (m.find()) { // log.info(m.group()+":"+m.start()+":"+m.end()); endPos.setValue(m.end()); return true; } return false; }
From source file:com.iana.boesc.utility.BOESCUtil.java
/** * this method change first character in upper case & return modified string * // ww w . j av a2s . co m * @param str * @return modified str */ public final String initCap(String rowStr) { StringBuffer stringbf = new StringBuffer(); Matcher m = Pattern.compile("([a-z])([a-z]*)", Pattern.CASE_INSENSITIVE).matcher(rowStr); while (m.find()) { m.appendReplacement(stringbf, m.group(1).toUpperCase() + m.group(2).toLowerCase()); } return stringbf.toString(); }
From source file:com.dreamlinx.automation.DINRelay.java
/** * Creates an HttpClient to communicate with the DIN relay. * @throws MalformedURLException/*w ww .j a v a 2s . c o m*/ * @throws HttpException * @throws IOException */ private void setupHttpClient() throws MalformedURLException, HttpException, IOException { httpClient = new HttpClient(); httpClient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); GetMethod getMethod = new GetMethod("http://" + ipAddress); int result = httpClient.executeMethod(getMethod); if (result != 200) { throw new HttpException(result + " - " + getMethod.getStatusText()); } String response = getMethod.getResponseBodyAsString(); getMethod.releaseConnection(); String regex = "name=\"Challenge\" value=\".*\""; Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(response); String challenge = ""; while (matcher.find()) { int start = matcher.start(0); int end = matcher.end(0); challenge = response.substring(start + 24, end - 1); } String md5Password = challenge + username + password + challenge; md5Password = toMD5(md5Password); PostMethod postMethod = new PostMethod("http://" + ipAddress + "/login.tgi"); postMethod.addParameter("Username", username); postMethod.addParameter("Password", md5Password); result = httpClient.executeMethod(postMethod); if (result != 200) { throw new HttpException(result + " - " + postMethod.getStatusText()); } postMethod.releaseConnection(); }
From source file:com.wordnik.swaggersocket.server.SwaggerSocketProtocolInterceptor.java
public SwaggerSocketProtocolInterceptor excludedheaders(String p) { if (p != null) { this.excludedheaders = Pattern.compile(p, Pattern.CASE_INSENSITIVE); }/*from w w w.j a v a 2 s .c om*/ return this; }
From source file:com.hp.alm.ali.idea.entity.tree.EntityNode.java
private boolean containsIgnoreCase(String str, String subStr) { return Pattern.compile(".*" + wildcardToRegex(subStr) + ".*", Pattern.CASE_INSENSITIVE).matcher(str) .matches();/*from w w w . j av a 2 s .c om*/ }