Example usage for java.util.regex Pattern LITERAL

List of usage examples for java.util.regex Pattern LITERAL

Introduction

In this page you can find the example usage for java.util.regex Pattern LITERAL.

Prototype

int LITERAL

To view the source code for java.util.regex Pattern LITERAL.

Click Source Link

Document

Enables literal parsing of the pattern.

Usage

From source file:com.github.xbn.regexutil.RegexGroupExtractor.java

/**
   <p>Create a new instance with a pattern <i>that contains groups</i>.</p>
        /*from ww w  .ja  v  a  2s.  c  o  m*/
 * @param  fieldable  May not be <code>null</code>.
 * @see  #RegexGroupExtractor(RegexGroupExtractor, String) this(rgx,s)
 * @see  #RegexGroupExtractor(RegexGroupExtractor) this(rgx)
 * @see  #RegexGroupExtractor(RegexGroupExtractor, String) this(rgx,s)
 * @see  #RegexGroupExtractor(RegexGroupExtractor, Pattern) this(rgx,p)
 */
public RegexGroupExtractor(RegexGroupExtractor_Fieldable fieldable) {

    iRqdGrps = fieldable.getRequiredGroups();
    if (iRqdGrps < 1 && iRqdGrps != -1) {
        throw new IllegalArgumentException(
                "fieldable.getRequiredGroups() (" + iRqdGrps + ") must be -1 or greater than zero.");
    }

    sph = (new SimplePatternHaser()).pattern(fieldable.getPattern(), "fieldable.getPattern()")
            .matcherUses(fieldable.getMatcherUses(), "fieldable.getMatcherUses()");
    getMatcherUses().crashIfForbiddenValue(MatcherUses.CUSTOM, "fieldable.getMatcherUses()", null);

    //Search the empty-string
    //So matcher can be reused (reset)
    m = getPattern().matcher("");

    if (BitBinaryUtil.doesIntHaveBit(getPattern().flags(), Pattern.LITERAL)) {
        throw new IllegalArgumentException("fieldable.getPattern() contains Pattern.LITERAL.");
    }
}

From source file:nl.hnogames.domoticz.Containers.DevicesInfo.java

public String[] getLevelNames() {
    return Pattern.compile("|", Pattern.LITERAL).split(LevelNames);
}

From source file:nl.hnogames.domoticzapi.Containers.DevicesInfo.java

public String[] getLevelNames() {
    if (UsefulBits.isEmpty(LevelNames))
        return null;
    String[] names = Pattern.compile("|", Pattern.LITERAL).split(LevelNames);
    String[] newNames = new String[names.length - 1];
    for (int i = 1; i < names.length; i++) {
        newNames[i - 1] = names[i];//  w  w  w.  j  ava 2s .c  o m
    }
    return newNames;
}

From source file:com.intuit.tank.tools.debugger.FindReplaceDialog.java

private void find(RSyntaxTextArea textArea) {

    try {/*w  w w  .  j a v  a 2  s  .co  m*/
        int offset = currentLine < textArea.getLineCount() ? textArea.getLineStartOffset(currentLine) : 0;
        String searchTerm = tfSearchEditor.getText();
        String text = textArea.getText();
        int foundIndex = -1;
        int flags = (checkboxRegexp.isSelected() ? 0 : Pattern.LITERAL)
                | (checkboxMatchCase.isSelected() ? 0 : Pattern.CASE_INSENSITIVE);
        Pattern p = Pattern.compile(searchTerm, flags);
        Matcher matcher = p.matcher(text);
        matcher.region(offset, text.length());
        if (matcher.find()) {
            foundIndex = matcher.start();
        } else if (checkboxWrap.isSelected() && offset > 0) {
            matcher.region(0, offset);
            if (matcher.find()) {
                foundIndex = matcher.start();
            }
        }
        if (foundIndex != -1) {
            int lineOfOffset = textArea.getLineOfOffset(foundIndex);
            // textArea.setActiveLineRange(lineOfOffset, lineOfOffset);
            textArea.setCurrentLine(lineOfOffset);
            // textArea.setCaretPosition(foundIndex + searchTerm.length());
            parent.repaint();
            parent.fireStepChanged(lineOfOffset);
            currentLine = lineOfOffset + 1;
        } else {
            JOptionPane.showMessageDialog(parent, "Search String not found.");
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.apache.nifi.processors.standard.EvaluateRegularExpression.java

int getCompileFlags(ProcessContext context) {
    int flags = (context.getProperty(UNIX_LINES).asBoolean() ? Pattern.UNIX_LINES : 0)
            | (context.getProperty(CASE_INSENSITIVE).asBoolean() ? Pattern.CASE_INSENSITIVE : 0)
            | (context.getProperty(COMMENTS).asBoolean() ? Pattern.COMMENTS : 0)
            | (context.getProperty(MULTILINE).asBoolean() ? Pattern.MULTILINE : 0)
            | (context.getProperty(LITERAL).asBoolean() ? Pattern.LITERAL : 0)
            | (context.getProperty(DOTALL).asBoolean() ? Pattern.DOTALL : 0)
            | (context.getProperty(UNICODE_CASE).asBoolean() ? Pattern.UNICODE_CASE : 0)
            | (context.getProperty(CANON_EQ).asBoolean() ? Pattern.CANON_EQ : 0)
            | (context.getProperty(UNICODE_CHARACTER_CLASS).asBoolean() ? Pattern.UNICODE_CHARACTER_CLASS : 0);
    return flags;
}

From source file:org.opennms.netmgt.collectd.HttpCollector.java

private static List<HttpCollectionAttribute> processResponse(final Locale responseLocale,
        final String responseBodyAsString, final HttpCollectionSet collectionSet,
        HttpCollectionResource collectionResource) {
    LOG.debug("processResponse:");
    LOG.debug("responseBody = {}", responseBodyAsString);
    LOG.debug("getmatches = {}", collectionSet.getUriDef().getUrl().getMatches());
    List<HttpCollectionAttribute> butes = new LinkedList<HttpCollectionAttribute>();
    int flags = 0;
    if (collectionSet.getUriDef().getUrl().getCanonicalEquivalence()) {
        flags |= Pattern.CANON_EQ;
    }/*from  w ww. ja  v  a  2s . c om*/
    if (collectionSet.getUriDef().getUrl().getCaseInsensitive()) {
        flags |= Pattern.CASE_INSENSITIVE;
    }
    if (collectionSet.getUriDef().getUrl().getComments()) {
        flags |= Pattern.COMMENTS;
    }
    if (collectionSet.getUriDef().getUrl().getDotall()) {
        flags |= Pattern.DOTALL;
    }
    if (collectionSet.getUriDef().getUrl().getLiteral()) {
        flags |= Pattern.LITERAL;
    }
    if (collectionSet.getUriDef().getUrl().getMultiline()) {
        flags |= Pattern.MULTILINE;
    }
    if (collectionSet.getUriDef().getUrl().getUnicodeCase()) {
        flags |= Pattern.UNICODE_CASE;
    }
    if (collectionSet.getUriDef().getUrl().getUnixLines()) {
        flags |= Pattern.UNIX_LINES;
    }
    LOG.debug("flags = {}", flags);
    Pattern p = Pattern.compile(collectionSet.getUriDef().getUrl().getMatches(), flags);
    Matcher m = p.matcher(responseBodyAsString);

    final boolean matches = m.matches();
    if (matches) {
        LOG.debug("processResponse: found matching attributes: {}", matches);
        final List<Attrib> attribDefs = collectionSet.getUriDef().getAttributes().getAttribCollection();
        final AttributeGroupType groupType = new AttributeGroupType(collectionSet.getUriDef().getName(),
                AttributeGroupType.IF_TYPE_ALL);

        final List<Locale> locales = new ArrayList<Locale>();
        if (responseLocale != null) {
            locales.add(responseLocale);
        }
        locales.add(Locale.getDefault());
        if (Locale.getDefault() != Locale.ENGLISH) {
            locales.add(Locale.ENGLISH);
        }

        for (final Attrib attribDef : attribDefs) {
            final String type = attribDef.getType();
            String value = null;
            try {
                value = m.group(attribDef.getMatchGroup());
            } catch (final IndexOutOfBoundsException e) {
                LOG.error(
                        "IndexOutOfBoundsException thrown while trying to find regex group, your regex does not contain the following group index: {}",
                        attribDef.getMatchGroup());
                LOG.error("Regex statement: {}", collectionSet.getUriDef().getUrl().getMatches());
                continue;
            }

            if (!type.matches("^([Oo](ctet|CTET)[Ss](tring|TRING))|([Ss](tring|TRING))$")) {
                Number num = null;
                for (final Locale locale : locales) {
                    try {
                        num = NumberFormat.getNumberInstance(locale).parse(value);
                        LOG.debug("processResponse: found a parsable number with locale \"{}\".", locale);
                        break;
                    } catch (final ParseException e) {
                        LOG.warn(
                                "attribute {} failed to match a parsable number with locale \"{}\"! Matched \"{}\" instead.",
                                attribDef.getAlias(), locale, value);
                    }
                }

                if (num == null) {
                    LOG.warn("processResponse: gave up attempting to parse numeric value, skipping group {}",
                            attribDef.getMatchGroup());
                    continue;
                }

                final HttpCollectionAttribute bute = new HttpCollectionAttribute(collectionResource,
                        new HttpCollectionAttributeType(attribDef, groupType), num);
                LOG.debug("processResponse: adding found numeric attribute: {}", bute);
                butes.add(bute);
            } else {
                HttpCollectionAttribute bute = new HttpCollectionAttribute(collectionResource,
                        new HttpCollectionAttributeType(attribDef, groupType), value);
                LOG.debug("processResponse: adding found string attribute: {}", bute);
                butes.add(bute);
            }
        }
    } else {
        LOG.debug("processResponse: found matching attributes: {}", matches);
    }
    return butes;
}

From source file:com.atwal.wakeup.battery.util.Utilities.java

public static SpannableString highlightKeywords(int color, String text, String keywords,
        boolean actionFirstMatch) {

    if (text != null && keywords != null && text.trim().length() == keywords.trim().length()) {
        return SpannableString.valueOf(text.trim());
    }/*from  w  ww  .  jav a2 s.c o m*/

    SpannableString s = new SpannableString(text);
    Pattern p = Pattern.compile(keywords, Pattern.LITERAL);
    Matcher m = p.matcher(s);
    while (m.find()) {
        int end = m.end();
        try {
            if (s.charAt(end) != ' ') {
                s.setSpan(new UnderlineSpan(), end, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            } else {
                s.setSpan(new UnderlineSpan(), end + 1, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (actionFirstMatch) {
            break;
        }
    }
    return s;
}

From source file:com.sssemil.sonyirremote.ir.ir.java

public static String normalisedVersion(String version, String sep, int maxWidth) {
    String[] split = Pattern.compile(sep, Pattern.LITERAL).split(version);
    StringBuilder sb = new StringBuilder();
    for (String s : split) {
        sb.append(String.format("%" + maxWidth + 's', s));
    }/*from  www  .jav  a 2s.c o m*/
    return sb.toString();
}

From source file:me.Wundero.Ray.utils.TextUtils.java

/**
 * Split the text object at a string reference. If skip, string will be
 * skipped.// w  ww .ja va  2 s  .co m
 */
public static List<Text> split(Text t, String s, boolean skip) {
    return split(t, Utils.compile(s, Pattern.LITERAL), skip);
}