本文整理汇总了Java中java.util.regex.Pattern.MULTILINE属性的典型用法代码示例。如果您正苦于以下问题:Java Pattern.MULTILINE属性的具体用法?Java Pattern.MULTILINE怎么用?Java Pattern.MULTILINE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.util.regex.Pattern
的用法示例。
在下文中一共展示了Pattern.MULTILINE属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updatePattern
void updatePattern() {
reset();
String p = bar.getPattern();
if (!bar.getRegularExpression()) {
p = Pattern.quote(p);
if (bar.getWholeWords()) {
p="\\b"+p+"\\b"; // NOI18N
}
}
int flags = Pattern.MULTILINE;
if (!bar.getMatchCase()) {
flags |= Pattern.CASE_INSENSITIVE;
}
try {
pattern = Pattern.compile(p, flags);
} catch (PatternSyntaxException psex) {
String message = NbBundle.getMessage(FindSupport.class, "FindBar.invalidExpression"); // NOI18N
StatusDisplayer.getDefault().setStatusText(message, StatusDisplayer.IMPORTANCE_FIND_OR_REPLACE);
}
findNext();
if (bar.getHighlightResults()) {
highlight(tc, false);
}
}
示例2: compile
@Override
public Pattern compile(String label)
{
int reFlags = 0;
if ((m_flags & SQLPatternFactory.CASE_SENSITIVE) == 0) {
reFlags |= Pattern.CASE_INSENSITIVE;
}
if ((m_flags & SQLPatternFactory.IGNORE_NEW_LINE) == 0) {
reFlags |= Pattern.DOTALL;
}
if ((m_flags & SQLPatternFactory.SINGLE_LINE) == 0) {
reFlags |= Pattern.MULTILINE;
}
String regex = generateExpression(0);
COMPILER_LOG.debug(String.format("PATTERN: %s: %s", label, regex));
return Pattern.compile(regex, reFlags);
}
示例3: toString
@Override
public String toString() {
StringBuilder f = new StringBuilder();
if ((flags & Pattern.CANON_EQ) != 0) f.append('c');
if ((flags & Pattern.CASE_INSENSITIVE) != 0) f.append('i');
if ((flags & Pattern.LITERAL) != 0) f.append('l');
if ((flags & Pattern.MULTILINE) != 0) f.append('m');
if ((flags & Pattern.DOTALL) != 0) f.append('s');
if ((flags & Pattern.UNICODE_CHARACTER_CLASS) != 0) f.append('U');
if ((flags & Pattern.UNICODE_CASE) != 0) f.append('u');
if ((flags & Pattern.COMMENTS) != 0) f.append('x');
String p = "/" + pattern + "/";
if (f.length() == 0) {
return singleLineToString(p);
}
return singleLineToString(p, f);
}
示例4: testFlags
public void testFlags() {
String[] supportedFlags = new String[]{"CASE_INSENSITIVE", "MULTILINE", "DOTALL", "UNICODE_CASE", "CANON_EQ", "UNIX_LINES",
"LITERAL", "COMMENTS", "UNICODE_CHAR_CLASS", "UNICODE_CHARACTER_CLASS"};
int[] flags = new int[]{Pattern.CASE_INSENSITIVE, Pattern.MULTILINE, Pattern.DOTALL, Pattern.UNICODE_CASE, Pattern.CANON_EQ,
Pattern.UNIX_LINES, Pattern.LITERAL, Pattern.COMMENTS, Regex.UNICODE_CHARACTER_CLASS};
Random random = random();
int num = 10 + random.nextInt(100);
for (int i = 0; i < num; i++) {
int numFlags = random.nextInt(flags.length + 1);
int current = 0;
StringBuilder builder = new StringBuilder();
for (int j = 0; j < numFlags; j++) {
int index = random.nextInt(flags.length);
current |= flags[index];
builder.append(supportedFlags[index]);
if (j < numFlags - 1) {
builder.append("|");
}
}
String flagsToString = Regex.flagsToString(current);
assertThat(Regex.flagsFromString(builder.toString()), equalTo(current));
assertThat(Regex.flagsFromString(builder.toString()), equalTo(Regex.flagsFromString(flagsToString)));
Pattern.compile("\\w\\d{1,2}", current); // accepts the flags?
}
}
示例5: patternToJoniFlags
private int patternToJoniFlags(int flags) {
int newFlags = 0;
if ((flags & Pattern.CASE_INSENSITIVE) != 0) {
newFlags |= Option.IGNORECASE;
}
if ((flags & Pattern.DOTALL) != 0) {
// This does NOT mean Pattern.MULTILINE
newFlags |= Option.MULTILINE;
}
if ((flags & Pattern.MULTILINE) != 0) {
// This is what Java 8's Nashorn engine does when using joni and
// translating Pattern's MULTILINE flag
newFlags &= ~Option.SINGLELINE;
newFlags |= Option.NEGATE_SINGLELINE;
}
return newFlags;
}
示例6: flagForChar
private int flagForChar(char c) {
switch (c) {
case 'c': return Pattern.CANON_EQ;
case 'i': return Pattern.CASE_INSENSITIVE;
case 'l': return Pattern.LITERAL;
case 'm': return Pattern.MULTILINE;
case 's': return Pattern.DOTALL;
case 'U': return Pattern.UNICODE_CHARACTER_CLASS;
case 'u': return Pattern.UNICODE_CASE;
case 'x': return Pattern.COMMENTS;
default:
throw new IllegalArgumentException("Unknown flag [" + c + "]");
}
}
示例7: flagsFromString
public static int flagsFromString(String flags) {
int pFlags = 0;
for (String s : Strings.delimitedListToStringArray(flags, "|")) {
if (s.isEmpty()) {
continue;
}
s = s.toUpperCase(Locale.ROOT);
if ("CASE_INSENSITIVE".equals(s)) {
pFlags |= Pattern.CASE_INSENSITIVE;
} else if ("MULTILINE".equals(s)) {
pFlags |= Pattern.MULTILINE;
} else if ("DOTALL".equals(s)) {
pFlags |= Pattern.DOTALL;
} else if ("UNICODE_CASE".equals(s)) {
pFlags |= Pattern.UNICODE_CASE;
} else if ("CANON_EQ".equals(s)) {
pFlags |= Pattern.CANON_EQ;
} else if ("UNIX_LINES".equals(s)) {
pFlags |= Pattern.UNIX_LINES;
} else if ("LITERAL".equals(s)) {
pFlags |= Pattern.LITERAL;
} else if ("COMMENTS".equals(s)) {
pFlags |= Pattern.COMMENTS;
} else if (("UNICODE_CHAR_CLASS".equals(s)) || ("UNICODE_CHARACTER_CLASS".equals(s))) {
pFlags |= UNICODE_CHARACTER_CLASS;
} else {
throw new IllegalArgumentException("Unknown regex flag [" + s + "]");
}
}
return pFlags;
}
示例8: flagsToString
public static String flagsToString(int flags) {
StringBuilder sb = new StringBuilder();
if ((flags & Pattern.CASE_INSENSITIVE) != 0) {
sb.append("CASE_INSENSITIVE|");
}
if ((flags & Pattern.MULTILINE) != 0) {
sb.append("MULTILINE|");
}
if ((flags & Pattern.DOTALL) != 0) {
sb.append("DOTALL|");
}
if ((flags & Pattern.UNICODE_CASE) != 0) {
sb.append("UNICODE_CASE|");
}
if ((flags & Pattern.CANON_EQ) != 0) {
sb.append("CANON_EQ|");
}
if ((flags & Pattern.UNIX_LINES) != 0) {
sb.append("UNIX_LINES|");
}
if ((flags & Pattern.LITERAL) != 0) {
sb.append("LITERAL|");
}
if ((flags & Pattern.COMMENTS) != 0) {
sb.append("COMMENTS|");
}
if ((flags & UNICODE_CHARACTER_CLASS) != 0) {
sb.append("UNICODE_CHAR_CLASS|");
}
return sb.toString();
}
示例9: parseFlags
public static int parseFlags(@Nullable BytesRef flagsString) {
int flags = 0;
if (flagsString == null) {
return flags;
}
for (char flag : flagsString.utf8ToString().toCharArray()) {
switch (flag) {
case 'i':
flags = flags | Pattern.CASE_INSENSITIVE;
break;
case 'u':
flags = flags | Pattern.UNICODE_CASE;
break;
case 'U':
flags = flags | Pattern.UNICODE_CHARACTER_CLASS;
break;
case 's':
flags = flags | Pattern.DOTALL;
break;
case 'm':
flags = flags | Pattern.MULTILINE;
break;
case 'x':
flags = flags | Pattern.COMMENTS;
break;
case 'd':
flags = flags | Pattern.UNIX_LINES;
break;
default:
break;
}
}
return flags;
}
示例10: flagsFromString
public static int flagsFromString(String flags) {
int pFlags = 0;
for (String s : Strings.delimitedListToStringArray(flags, "|")) {
if (s.isEmpty()) {
continue;
}
s = s.toUpperCase(Locale.ROOT);
if ("CASE_INSENSITIVE".equals(s)) {
pFlags |= Pattern.CASE_INSENSITIVE;
} else if ("MULTILINE".equals(s)) {
pFlags |= Pattern.MULTILINE;
} else if ("DOTALL".equals(s)) {
pFlags |= Pattern.DOTALL;
} else if ("UNICODE_CASE".equals(s)) {
pFlags |= Pattern.UNICODE_CASE;
} else if ("CANON_EQ".equals(s)) {
pFlags |= Pattern.CANON_EQ;
} else if ("UNIX_LINES".equals(s)) {
pFlags |= Pattern.UNIX_LINES;
} else if ("LITERAL".equals(s)) {
pFlags |= Pattern.LITERAL;
} else if ("COMMENTS".equals(s)) {
pFlags |= Pattern.COMMENTS;
} else if ("UNICODE_CHAR_CLASS".equals(s)) {
pFlags |= UNICODE_CHARACTER_CLASS;
} else {
throw new IllegalArgumentException("Unknown regex flag [" + s + "]");
}
}
return pFlags;
}
示例11: joniToPatternFlags
private int joniToPatternFlags(int flags) {
int newFlags = 0;
if ((flags & Option.IGNORECASE) != 0) {
newFlags |= Pattern.CASE_INSENSITIVE;
}
// This does NOT mean Pattern.MULTILINE, this is equivalent to Pattern.DOTALL
if ((flags & Option.MULTILINE) != 0) {
newFlags |= Pattern.DOTALL;
}
// This means Pattern.MULTILINE. Nice
if ((flags & Option.NEGATE_SINGLELINE) != 0) {
newFlags |= Pattern.MULTILINE;
}
return newFlags;
}
示例12: compilePattern
private Pattern compilePattern(String sectionName) {
int flags = Pattern.DOTALL | Pattern.MULTILINE;
return Pattern.compile(".*^\\s*?//\\s*?KEEP " + sectionName + ".*?\n(.*?)^\\s*// KEEP " + sectionName
+ " END.*?\n", flags);
}
示例13: getNextMatchPosRegExImpl
/**
* Searches <code>searchIn</code> for an occurrence of <code>regEx</code>
* either forwards or backwards, matching case or not.
*
* @param regEx The regular expression to look for.
* @param searchIn The string to search in.
* @param goForward Whether to search forward. If <code>false</code>,
* search backward.
* @param matchCase Whether or not to do a case-sensitive search for
* <code>regEx</code>.
* @param wholeWord If <code>true</code>, <code>regEx</code>
* occurrences embedded in longer words in <code>searchIn</code>
* don't count as matches.
* @param replaceStr The string that will replace the match found (if
* a match is found). The object returned will contain the
* replacement string with matched groups substituted. If this
* value is <code>null</code>, it is assumed this call is part of a
* "find" instead of a "replace" operation.
* @return If <code>replaceStr</code> is <code>null</code>, a
* <code>Point</code> representing the starting and ending points
* of the match. If it is non-<code>null</code>, an object with
* information about the match and the morphed string to replace
* it with. If no match is found, <code>null</code> is returned.
* @throws PatternSyntaxException If <code>regEx</code> is an invalid
* regular expression.
* @throws IndexOutOfBoundsException If <code>replaceStr</code> references
* an invalid group (less than zero or greater than the number of
* groups matched).
* @see #getNextMatchPos
*/
private static Object getNextMatchPosRegExImpl(String regEx,
CharSequence searchIn, boolean goForward,
boolean matchCase, boolean wholeWord,
String replaceStr) {
if (wholeWord) {
regEx = "\\b" + regEx + "\\b";
}
// Make a pattern that takes into account whether or not to match case.
int flags = Pattern.MULTILINE; // '^' and '$' are done per line.
flags = RSyntaxUtilities.getPatternFlags(matchCase, flags);
Pattern pattern = null;
try {
pattern = Pattern.compile(regEx, flags);
} catch (PatternSyntaxException pse) {
return null; // e.g. a "mark all" request with incomplete regex
}
// Make a Matcher to find the regEx instances.
Matcher m = pattern.matcher(searchIn);
// Search forwards
if (goForward) {
if (m.find()) {
if (replaceStr==null) { // Find, not replace.
return new Point(m.start(), m.end());
}
// Otherwise, replace
return new RegExReplaceInfo(m.group(0),
m.start(), m.end(),
getReplacementText(m, replaceStr));
}
}
// Search backwards
else {
List<?> matches = getMatches(m, replaceStr);
if (!matches.isEmpty()) {
return matches.get(matches.size()-1);
}
}
return null; // No match found
}