java.util.regex.PatternSyntaxException Java Examples
The following examples show how to use
java.util.regex.PatternSyntaxException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CompileCommandsJsonParserOptionPage.java From cmake4eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public void performApply(IProgressMonitor monitor) throws CoreException { // normally should be handled by LanguageSettingsProviderTab final String text = pattern.getText(); try { Pattern.compile(text); } catch (PatternSyntaxException ex) { // BUG in CDT: core exceptions thrown here are not visible to users. CDT-WTF // IStatus status = new Status(IStatus.ERROR, Plugin.PLUGIN_ID, // IStatus.OK, // "invalid suffix pattern in CMAKE_EXPORT_COMPILE_COMMANDS Parser", ex); // throw new CoreException(status); throw new PatternSyntaxException( "Invalid suffix pattern in CMAKE_EXPORT_COMPILE_COMMANDS Parser:\n" + ex.getDescription(), ex.getPattern(), ex.getIndex()); } }
Example #2
Source File: JApiCmpMojo.java From japicmp with Apache License 2.0 | 6 votes |
private void filterVersionPattern(List<ArtifactVersion> availableVersions, PluginParameters pluginParameters) throws MojoFailureException { if (pluginParameters.getParameterParam() != null && pluginParameters.getParameterParam().getOldVersionPattern() != null) { String versionPattern = pluginParameters.getParameterParam().getOldVersionPattern(); Pattern pattern; try { pattern = Pattern.compile(versionPattern); } catch (PatternSyntaxException e) { throw new MojoFailureException("Could not compile provided versionPattern '" + versionPattern + "' as regular expression: " + e.getMessage(), e); } for (Iterator<ArtifactVersion> versionIterator = availableVersions.iterator(); versionIterator.hasNext(); ) { ArtifactVersion version = versionIterator.next(); Matcher matcher = pattern.matcher(version.toString()); if (!matcher.matches()) { versionIterator.remove(); if (getLog().isDebugEnabled()) { getLog().debug("Filtering version '" + version.toString() + "' because it does not match configured versionPattern '" + versionPattern + "'."); } } } } else { getLog().debug("Parameter <oldVersionPattern> not configured, i.e. no version filtered."); } }
Example #3
Source File: Index.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
/** * regexPatternMatch * * @param regex * @param word * @return */ private static boolean regexPatternMatch(String regex, String word, boolean caseSensitive) { Pattern pattern = PATTERNS.get(regex); if (pattern == null) { try { // compile the pattern pattern = (caseSensitive) ? Pattern.compile(regex) : Pattern.compile(regex, Pattern.CASE_INSENSITIVE); // cache for later PATTERNS.put(regex, pattern); } catch (PatternSyntaxException e) { } } return (pattern != null) ? pattern.matcher(word).find() : false; }
Example #4
Source File: KfsBusinessObjectMetaDataServiceImpl.java From kfs with GNU Affero General Public License v3.0 | 6 votes |
@Override public List<BusinessObjectProperty> findBusinessObjectProperties(String namespaceCode, String componentLabel, String propertyLabel) { List<BusinessObjectComponent> businessObjectComponents = findBusinessObjectComponents(namespaceCode, componentLabel); Pattern propertyLabelRegex = null; if (StringUtils.isNotBlank(propertyLabel)) { String patternStr = propertyLabel.replace("*", ".*").toUpperCase(); try { propertyLabelRegex = Pattern.compile(patternStr); } catch (PatternSyntaxException ex) { LOG.error("KfsBusinessObjectMetaDataServiceImpl unable to parse propertyLabel pattern, ignoring.", ex); } } List<BusinessObjectProperty> matchingBusinessObjectProperties = new ArrayList<BusinessObjectProperty>(); for (BusinessObjectComponent businessObjectComponent : businessObjectComponents) { for (AttributeDefinition attributeDefinition : dataDictionaryService.getDataDictionary().getBusinessObjectEntry(businessObjectComponent.getComponentClass().toString()).getAttributes()) { if (!attributeDefinition.getName().endsWith(KFSPropertyConstants.VERSION_NUMBER) && !attributeDefinition.getName().endsWith(KFSPropertyConstants.OBJECT_ID) && ((propertyLabelRegex == null) || propertyLabelRegex.matcher(attributeDefinition.getLabel().toUpperCase()).matches())) { matchingBusinessObjectProperties.add(new BusinessObjectProperty(businessObjectComponent, attributeDefinition)); } } } return matchingBusinessObjectProperties; }
Example #5
Source File: ImportsUtilBase.java From KodeBeagle with Apache License 2.0 | 6 votes |
public final Map<String, Set<String>> excludeConfiguredImports( final Map<String, Set<String>> importsVsMethods, final Set<String> excludeImports) { Map<String, Set<String>> finalImportsVsMethods = new HashMap<>(); finalImportsVsMethods.putAll(importsVsMethods); Set<Map.Entry<String, Set<String>>> entrySet = importsVsMethods.entrySet(); for (String importStatement : excludeImports) { Pattern pattern = Pattern.compile(importStatement); for (Map.Entry<String, Set<String>> entry : entrySet) { try { String entryImport = entry.getKey(); Matcher matcher = pattern.matcher(entryImport); if (matcher.find()) { finalImportsVsMethods.remove(entryImport); } } catch (PatternSyntaxException e) { KBNotification.getInstance().error(e); e.printStackTrace(); } } } return finalImportsVsMethods; }
Example #6
Source File: OpenSourceLicenseCheckMojo.java From license-check with MIT License | 6 votes |
List<Pattern> getAsPatternList(final String[] src) { final List<Pattern> target = new ArrayList<Pattern>(); if (src != null) { for (final String s : src) { try { final Pattern pattern = Pattern.compile(s); target.add(pattern); } catch (final PatternSyntaxException e) { getLog().warn("The regex " + s + " is invalid: " + e.getLocalizedMessage()); } } } return target; }
Example #7
Source File: BasicConfigurationService.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Converts the given list of Strings to a list of Pattern objects * * @param regexps * A list of regex pattern strings * * @exception IllegalArgumentException * if one of the patterns has invalid regular expression * syntax */ private List<Pattern> getRegExPatterns(List<String> regexps) { ArrayList<Pattern> patterns = new ArrayList<>(); for (String regexp : regexps) { String regex = StringUtils.trimToNull(regexp); if (regex != null) { // if :empty: is in any of the then return an empty list if (StringUtils.equals(":empty:", regex)) return new ArrayList<>(); try { patterns.add(Pattern.compile(regex, Pattern.CASE_INSENSITIVE)); } catch (PatternSyntaxException e) { throw new IllegalArgumentException("Illegal Regular Expression Syntax: [" + regex + "] - " + e.getMessage()); } } } return patterns; }
Example #8
Source File: Oracle8Builder.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Creates a new builder instance. * * @param platform The plaftform this builder belongs to */ public Oracle8Builder(Platform platform) { super(platform); addEscapedCharSequence("'", "''"); try { _isoDatePattern = Pattern.compile("\\d{4}\\-\\d{2}\\-\\d{2}"); _isoTimePattern = Pattern.compile("\\d{2}:\\d{2}:\\d{2}"); _isoTimestampPattern = Pattern.compile("\\d{4}\\-\\d{2}\\-\\d{2} \\d{2}:\\d{2}:\\d{2}[\\.\\d{1,8}]?"); } catch (PatternSyntaxException ex) { throw new DdlUtilsException(ex); } }
Example #9
Source File: DupeCheckHooks.java From drftpd with GNU General Public License v2.0 | 6 votes |
private void loadConf() { Properties cfg = ConfigLoader.loadPluginConfig("dupecheck.conf"); String exempt = cfg.getProperty("exempt"); String type = cfg.getProperty("type"); if (exempt != null) { _exempt = null; try { _exempt = Pattern.compile(exempt.trim()); logger.debug("Exempt pattern parsed and compiled succesffull [{}]", _exempt.toString()); } catch(PatternSyntaxException pse) { logger.error("Provided exempt pattern is incorrectly formatted", pse); } } if (type != null) { _type = Integer.parseInt(type.trim()); if (_type < 0 || _type > 3) { logger.error("Incorrect type {} found, ignoring and disabling dupechecking", type); _type = 0; } } logger.info("Dupe checking type has been set to {}", _type); }
Example #10
Source File: ValidPatternVisitor.java From datawave with Apache License 2.0 | 6 votes |
/** * Parse a literal value and put into the pattern cache if it does not exist. * * @param node */ public void parseAndPutPattern(JexlNode node) { // Catch the situation where a user might enter FIELD1 !~ VALUE1 Object literalValue = JexlASTHelper.getLiteralValue(node); if (literalValue != null && String.class.equals(literalValue.getClass())) { String literalString = (String) literalValue; try { if (patternCache.containsKey(literalString)) { return; } patternCache.put(literalString, Pattern.compile(literalString)); } catch (PatternSyntaxException e) { String builtNode = JexlStringBuildingVisitor.buildQueryWithoutParse(node); String errMsg = "Invalid pattern found in filter function '" + builtNode + "'"; throw new PatternSyntaxException(errMsg, e.getPattern(), e.getIndex()); } } }
Example #11
Source File: AggregationOperator.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
private Attribute[] getAttributesArrayFromRegex(Attributes attributes, String regex) throws OperatorException { Pattern pattern = null; try { pattern = Pattern.compile(regex); } catch (PatternSyntaxException e) { throw new UserError(this, 206, regex, e.getMessage()); } List<Attribute> attributeList = new LinkedList<>(); Iterator<Attribute> i = attributes.allAttributes(); while (i.hasNext()) { Attribute attribute = i.next(); Matcher matcher = pattern.matcher(attribute.getName()); if (matcher.matches()) { attributeList.add(attribute); } } Attribute[] attributesArray = new Attribute[attributeList.size()]; attributesArray = attributeList.toArray(attributesArray); return attributesArray; }
Example #12
Source File: XmlSecInInterceptor.java From cxf with Apache License 2.0 | 6 votes |
private Collection<Pattern> getSubjectContraints(Message msg) throws PatternSyntaxException { String certConstraints = (String)SecurityUtils.getSecurityPropertyValue(SecurityConstants.SUBJECT_CERT_CONSTRAINTS, msg); // Check the message property first. If this is not null then use it. Otherwise pick up // the constraints set as a property if (certConstraints != null) { String[] certConstraintsList = certConstraints.split(","); if (certConstraintsList != null) { subjectDNPatterns.clear(); for (String certConstraint : certConstraintsList) { subjectDNPatterns.add(Pattern.compile(certConstraint.trim())); } } } return subjectDNPatterns; }
Example #13
Source File: JimfsWindowsLikeFileSystemTest.java From jimfs with Apache License 2.0 | 6 votes |
@Test public void testPathMatchers_glob() { assertThatPath("bar").matches("glob:bar"); assertThatPath("bar").matches("glob:*"); assertThatPath("C:\\foo").doesNotMatch("glob:*"); assertThatPath("C:\\foo\\bar").doesNotMatch("glob:*"); assertThatPath("C:\\foo\\bar").matches("glob:**"); assertThatPath("C:\\foo\\bar").matches("glob:C:\\\\**"); assertThatPath("foo\\bar").doesNotMatch("glob:C:\\\\**"); assertThatPath("C:\\foo\\bar\\baz\\stuff").matches("glob:C:\\\\foo\\\\**"); assertThatPath("C:\\foo\\bar\\baz\\stuff").matches("glob:C:\\\\**\\\\stuff"); assertThatPath("C:\\foo").matches("glob:C:\\\\[a-z]*"); assertThatPath("C:\\Foo").matches("glob:C:\\\\[a-z]*"); assertThatPath("C:\\foo").matches("glob:C:\\\\[A-Z]*"); assertThatPath("C:\\Foo").matches("glob:C:\\\\[A-Z]*"); assertThatPath("C:\\foo\\bar\\baz\\Stuff.java").matches("glob:**\\\\*.java"); assertThatPath("C:\\foo\\bar\\baz\\Stuff.java").matches("glob:**\\\\*.{java,class}"); assertThatPath("C:\\foo\\bar\\baz\\Stuff.class").matches("glob:**\\\\*.{java,class}"); assertThatPath("C:\\foo\\bar\\baz\\Stuff.java").matches("glob:**\\\\*.*"); try { fs.getPathMatcher("glob:**\\*.{java,class"); fail(); } catch (PatternSyntaxException expected) { } }
Example #14
Source File: RegexSelector.java From zongtui-webcrawler with GNU General Public License v2.0 | 6 votes |
public RegexSelector(String regexStr, int group) { if (StringUtils.isBlank(regexStr)) { throw new IllegalArgumentException("regex must not be empty"); } // Check bracket for regex group. Add default group 1 if there is no group. // Only check if there exists the valid left parenthesis, leave regexp validation for Pattern. if (StringUtils.countMatches(regexStr, "(") - StringUtils.countMatches(regexStr, "\\(") == StringUtils.countMatches(regexStr, "(?:") - StringUtils.countMatches(regexStr, "\\(?:")) { regexStr = "(" + regexStr + ")"; } this.regexStr = regexStr; try { regex = Pattern.compile(regexStr, Pattern.DOTALL | Pattern.CASE_INSENSITIVE); } catch (PatternSyntaxException e) { throw new IllegalArgumentException("invalid regex", e); } this.group = group; }
Example #15
Source File: PreferencesController.java From cyberduck with GNU General Public License v3.0 | 6 votes |
public void downloadSkipRegexFieldDidChange(final NSNotification sender) { String value = this.downloadSkipRegexField.string().trim(); if(StringUtils.EMPTY.equals(value)) { preferences.setProperty("queue.download.skip.enable", false); preferences.setProperty("queue.download.skip.regex", value); this.downloadSkipButton.setState(NSCell.NSOffState); } try { Pattern compiled = Pattern.compile(value); preferences.setProperty("queue.download.skip.regex", compiled.pattern()); this.mark(this.downloadSkipRegexField.textStorage(), null); } catch(PatternSyntaxException e) { this.mark(this.downloadSkipRegexField.textStorage(), e); } }
Example #16
Source File: FileNameController.java From netbeans with Apache License 2.0 | 6 votes |
/** * Sets proper color of file pattern. */ private void updateFileNamePatternColor() { boolean wasInvalid = patternValid; String pattern = getFileNamePattern(); if (pattern == null || pattern.isEmpty()) { patternValid = true; } else { try { Pattern p = RegexpUtil.makeFileNamePattern( SearchScopeOptions.create(getFileNamePattern(), regexp)); if (p == null) { patternValid = false; } else { patternValid = true; } } catch (PatternSyntaxException e) { patternValid = false; } } if (patternValid != wasInvalid && !isAllFilesInfoDisplayed()) { fileNamePatternEditor.setForeground( patternValid ? defaultColor : UiUtils.getErrorTextColor()); } }
Example #17
Source File: TransitionLabelParserRecursive.java From RegexStaticAnalysis with MIT License | 6 votes |
private char parseEscapedUnicodeCharacter() { consumeSymbol(); StringBuilder hexNumberStr = new StringBuilder(); /* Read next four symbols as hex number */ hexNumberStr.append(currentSymbol); for (int i = 0; i < 4; i++) { consumeSymbol(); hexNumberStr.append(currentSymbol); } try { int hexNumber = Integer.parseInt(hexNumberStr.toString(), 16); if (hexNumber >= MAX_16UNICODE) { throw new PatternSyntaxException("Hexadecimal codepoint is too big", transitionLabelString, index); } return ((char) hexNumber); } catch (NumberFormatException nfe) { throw new PatternSyntaxException("Illegal hexadecimal escape sequence", transitionLabelString, index); } }
Example #18
Source File: BasicSearchCriteria.java From netbeans with Apache License 2.0 | 6 votes |
/** * Returns a {@link Pattern} object corresponding to the substring pattern * specified in the criteria. * * @return {@code Pattern} object, or {@code null} if no pattern has been * specified */ Pattern getTextPattern() { if (!textPatternValid || !textPatternSpecified) { return null; } if (textPattern != null) { return textPattern; } try { return TextRegexpUtil.makeTextPattern(searchPattern); } catch (PatternSyntaxException e) { textPatternValid = false; return null; } }
Example #19
Source File: Validation.java From freeacs with MIT License | 5 votes |
/** * @param args * @param str * @return * @deprecated - use matches() instead */ public static boolean filter(String[] args, String str) { String patternStr = null; boolean equal = true; if (args.length > 1) { patternStr = args[1]; if (patternStr.startsWith("!")) { patternStr = patternStr.substring(1); equal = false; } } if (patternStr != null) { Pattern pattern; try { pattern = Pattern.compile(patternStr, Pattern.CASE_INSENSITIVE); } catch (PatternSyntaxException pse) { throw new IllegalArgumentException( "The filter argument is not allowed: " + pse.getMessage() + "(reason may be not expanded variable)"); } Matcher matcher = pattern.matcher(str); if (matcher.find()) { return !equal; } else { return equal; } } return false; }
Example #20
Source File: MetricTreeTest.java From graphouse with Apache License 2.0 | 5 votes |
public static Pattern createPattern(final String globPattern) { String result = globPattern.replace("*", "[-_0-9a-zA-Z]*"); result = result.replace("?", "[-_0-9a-zA-Z]"); try { return Pattern.compile(result); } catch (PatternSyntaxException e) { return null; } }
Example #21
Source File: PatternUtils.java From nevo-decorators-sms-captchas with GNU General Public License v3.0 | 5 votes |
public static Pattern compilePattern(String pattern, String def ,int flags) { try { return Pattern.compile(pattern ,flags); } catch (PatternSyntaxException ignored) { } return Pattern.compile(def ,flags); }
Example #22
Source File: Element.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Find elements whose text matches the supplied regular expression. * @param regex regular expression to match text against. You can use <a href="http://java.sun.com/docs/books/tutorial/essential/regex/pattern.html#embedded">embedded flags</a> (such as (?i) and (?m) to control regex options. * @return elements matching the supplied regular expression. * @see Element#ownText() */ public Elements getElementsMatchingOwnText(String regex) { Pattern pattern; try { pattern = Pattern.compile(regex); } catch (PatternSyntaxException e) { throw new IllegalArgumentException("Pattern syntax error: " + regex, e); } return getElementsMatchingOwnText(pattern); }
Example #23
Source File: ThreadDumper.java From spark with GNU General Public License v3.0 | 5 votes |
public Regex(Set<String> namePatterns) { this.namePatterns = namePatterns.stream() .map(regex -> { try { return Pattern.compile(regex, Pattern.CASE_INSENSITIVE); } catch (PatternSyntaxException e) { return null; } }) .filter(Objects::nonNull) .collect(Collectors.toSet()); }
Example #24
Source File: JdkRegExp.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Construct a Regular expression from the given {@code source} and {@code flags} strings. * * @param source RegExp source string * @param flags RegExp flag string * @throws ParserException if flags is invalid or source string has syntax error. */ public JdkRegExp(final String source, final String flags) throws ParserException { super(source, flags); int intFlags = 0; if (isIgnoreCase()) { intFlags |= CASE_INSENSITIVE | UNICODE_CASE; } if (isMultiline()) { intFlags |= MULTILINE; } try { RegExpScanner parsed; try { parsed = RegExpScanner.scan(source); } catch (final PatternSyntaxException e) { // refine the exception with a better syntax error, if this // passes, just rethrow what we have Pattern.compile(source, intFlags); throw e; } if (parsed != null) { this.pattern = Pattern.compile(parsed.getJavaPattern(), intFlags); this.groupsInNegativeLookahead = parsed.getGroupsInNegativeLookahead(); } } catch (final PatternSyntaxException e2) { throwParserException("syntax", e2.getMessage()); } }
Example #25
Source File: Element.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Find elements whose text matches the supplied regular expression. * @param regex regular expression to match text against. You can use <a href="http://java.sun.com/docs/books/tutorial/essential/regex/pattern.html#embedded">embedded flags</a> (such as (?i) and (?m) to control regex options. * @return elements matching the supplied regular expression. * @see Element#text() */ public Elements getElementsMatchingText(String regex) { Pattern pattern; try { pattern = Pattern.compile(regex); } catch (PatternSyntaxException e) { throw new IllegalArgumentException("Pattern syntax error: " + regex, e); } return getElementsMatchingText(pattern); }
Example #26
Source File: TransitionLabelParserRecursive.java From RegexStaticAnalysis with MIT License | 5 votes |
private char parseEscapedOctalCharacter() { consumeSymbol(); StringBuilder hexNumberStr = new StringBuilder(); int i = 0; /* Read octal symbols until larger than allowed max up to a maximum of three characters */ int tmpNum = 0; while (tmpNum < 0377 && currentSymbol.matches("[0-7]") && i < 3) { hexNumberStr.append(currentSymbol); tmpNum = Integer.parseInt(hexNumberStr.toString(), 8); i++; if (!consumeSymbol()) { break; } } try { int hexNumber = Integer.parseInt(hexNumberStr.toString(), 8); if (hexNumber >= MAX_16UNICODE) { throw new PatternSyntaxException("Hexadecimal codepoint is too big", transitionLabelString, index); } return ((char) hexNumber); } catch (NumberFormatException nfe) { throw new PatternSyntaxException("Illegal hexadecimal escape sequence", transitionLabelString, index); } }
Example #27
Source File: SynthParser.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private void startBind(Attributes attributes) throws SAXException { ParsedSynthStyle style = null; String path = null; int type = -1; for(int i = attributes.getLength() - 1; i >= 0; i--) { String key = attributes.getQName(i); if (key.equals(ATTRIBUTE_STYLE)) { style = (ParsedSynthStyle)lookup(attributes.getValue(i), ParsedSynthStyle.class); } else if (key.equals(ATTRIBUTE_TYPE)) { String typeS = attributes.getValue(i).toUpperCase(); if (typeS.equals("NAME")) { type = DefaultSynthStyleFactory.NAME; } else if (typeS.equals("REGION")) { type = DefaultSynthStyleFactory.REGION; } else { throw new SAXException("bind: unknown type " + typeS); } } else if (key.equals(ATTRIBUTE_KEY)) { path = attributes.getValue(i); } } if (style == null || path == null || type == -1) { throw new SAXException("bind: you must specify a style, type " + "and key"); } try { _factory.addStyle(style, path, type); } catch (PatternSyntaxException pse) { throw new SAXException("bind: " + path + " is not a valid " + "regular expression"); } }
Example #28
Source File: SynthParser.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private void startBind(Attributes attributes) throws SAXException { ParsedSynthStyle style = null; String path = null; int type = -1; for(int i = attributes.getLength() - 1; i >= 0; i--) { String key = attributes.getQName(i); if (key.equals(ATTRIBUTE_STYLE)) { style = (ParsedSynthStyle)lookup(attributes.getValue(i), ParsedSynthStyle.class); } else if (key.equals(ATTRIBUTE_TYPE)) { String typeS = attributes.getValue(i).toUpperCase(); if (typeS.equals("NAME")) { type = DefaultSynthStyleFactory.NAME; } else if (typeS.equals("REGION")) { type = DefaultSynthStyleFactory.REGION; } else { throw new SAXException("bind: unknown type " + typeS); } } else if (key.equals(ATTRIBUTE_KEY)) { path = attributes.getValue(i); } } if (style == null || path == null || type == -1) { throw new SAXException("bind: you must specify a style, type " + "and key"); } try { _factory.addStyle(style, path, type); } catch (PatternSyntaxException pse) { throw new SAXException("bind: " + path + " is not a valid " + "regular expression"); } }
Example #29
Source File: HtmlUbbUtil.java From Zettelkasten with GNU General Public License v3.0 | 5 votes |
/** * This method converts special chars of highlighted segments keywords into * chars which can be read by a CSS-style-sheet. If, for instance, the user * has assigned a text segement with a keyword that contains umlauts, spaces * or other special chars, these chars cannot be used to declare a * CSS-class. In this case, all these chars are replaced by a "_". * * @param content the entry's content * @return the entry's content with all appearing highlight-segment-keywords * converted */ private static String convertUbbHighlightSegments(String content) { try { // create a pattern from the first search term. if it fails, go on // to the catch-block, else contiue here. Matcher m = Pattern.compile("\\[s ([^\\[]*)\\]").matcher(content); // find all matches and copy the start/end-positions to our arraylist // we now can easily retrieve the found terms and their positions via this // array, thus navigation with find-next and find-prev-buttons is simple while (m.find()) { for (int cnt = 0; cnt < m.groupCount(); cnt++) { String segword = m.group(cnt); String segpart = segword.substring(3); segpart = segpart.replace(" ", "_") .replace(":", "_") .replace("/", "_") .replace("ß", "ss") .replace("ä", "ae") .replace("ö", "oe") .replace("ü", "ue") .replace("Ä", "Ae") .replace("Ö", "Oe") .replace("Ü", "Ue") .replace("\\", "_"); content = content.replace(segword, "[s " + segpart); } } } catch (PatternSyntaxException | IndexOutOfBoundsException e) { // and leave method return content; } return content; }
Example #30
Source File: PatternTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testOrphanQuantifiers() { try { Pattern.compile("+++++"); fail("PatternSyntaxException expected"); } catch (PatternSyntaxException pse) { } }