List of usage examples for java.util.regex Pattern MULTILINE
int MULTILINE
To view the source code for java.util.regex Pattern MULTILINE.
Click Source Link
From source file:gate.creole.kea.CorpusImporter.java
protected boolean annotateKeyPhrases(Document document, String annSetName, String keyphraseAnnotationType, List<String> phrases) throws Exception { if (phrases == null || phrases.isEmpty()) return false; //create a pattern String patternStr = ""; Iterator<String> phraseIter = phrases.iterator(); while (phraseIter.hasNext()) { String phrase = phraseIter.next(); patternStr += patternStr.length() == 0 ? "\\Q" + phrase + "\\E" : "|\\Q" + phrase + "\\E"; }/* w w w. ja va2s. c o m*/ Pattern pattern = Pattern.compile(patternStr, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); Matcher matcher = pattern.matcher(document.getContent().toString()); AnnotationSet outputSet = annSetName == null || annSetName.length() == 0 ? document.getAnnotations() : document.getAnnotations(annSetName); boolean result = false; while (matcher.find()) { int start = matcher.start(); int end = matcher.end(); outputSet.add(new Long(start), new Long(end), keyphraseAnnotationType, Factory.newFeatureMap()); result = true; } document.getFeatures().put("Author assigned keyphrases", phrases); return result; }
From source file:org.apache.asterix.test.aql.TestExecutor.java
public void runScriptAndCompareWithResultRegexAdm(File scriptFile, File expectedFile, File actualFile) throws Exception { StringWriter actual = new StringWriter(); StringWriter expected = new StringWriter(); IOUtils.copy(new FileInputStream(actualFile), actual, StandardCharsets.UTF_8); IOUtils.copy(new FileInputStream(expectedFile), expected, StandardCharsets.UTF_8); Pattern pattern = Pattern.compile(expected.toString(), Pattern.DOTALL | Pattern.MULTILINE); if (!pattern.matcher(actual.toString()).matches()) { throw new Exception("Result for " + scriptFile + ": actual file did not match expected result"); }/*w ww. j a v a2s . c o m*/ }
From source file:de.javakaffee.kryoserializers.KryoTest.java
@Test(enabled = true) public void testCopyRegex() throws Exception { final Holder<Pattern> pattern = new Holder<Pattern>(Pattern.compile("regex")); final Holder<Pattern> copy = _kryo.copy(pattern); assertDeepEquals(copy, pattern);//from w w w . j ava 2 s. c o m final Holder<Pattern> patternWithFlags = new Holder<Pattern>( Pattern.compile("\n", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE)); final Holder<Pattern> copyWithFlags = _kryo.copy(patternWithFlags); assertDeepEquals(copyWithFlags, patternWithFlags); }
From source file:com.github.rwitzel.streamflyer.regex.RegexModifierTest.java
@Ignore @Test// www . j av a2 s . c o m public void testRemovalAtTheStartOfLine_usingMultiLineFlag() throws Exception { String endlessAbc = StringUtils.repeat("abc", 10000); String regex = "^abc"; int flags = Pattern.MULTILINE; String replacement = ""; String input = "\nabc" + endlessAbc + "\nabc" + endlessAbc + "\nabc" + endlessAbc; String expectedOutput = "\n" + endlessAbc + "\n" + endlessAbc + "\n" + endlessAbc; int lookBehind = 1; int capacityCharBuf = 3; assertReplacement(input, regex, replacement, lookBehind, capacityCharBuf, expectedOutput, flags); }
From source file:org.extensiblecatalog.ncip.v2.millennium.MillenniumRemoteServiceManager.java
public itemCirculation getItemStatusList(String html) { // You can turn on these lines below for quick test with your LOCAL modify page /*//from w w w . j ava 2 s . c o m MillenniumFileHandle millenniumFileHandle = new MillenniumFileHandle(); String html = ""; html = millenniumFileHandle.ReadTextFile("H:\\My Documents\\LookupItem Test Case.txt"); LOG.debug(html); */ int i = 0; Status iStatus = new Status(); itemCirculation itemCirculationStatus = new itemCirculation(); ArrayList<ItemStatus> itemStatusList = new ArrayList<ItemStatus>(); boolean itemFound = false; boolean additionalItem = false; boolean circulationFound = true; boolean callnoFound = true; boolean locationFound = true; // Searching html to find if it has more additional copies of item status Pattern additionCopyPattern = Pattern.compile( "^(.*?)center><form method=(?s)(.*?)post(.*?)(?s)(.*?)action=(?s)(.*?)>(.*?)<input type(.*?)(?s)(.*?)submit(?s)(.*?)value=(?s)(.*?)/>$", Pattern.MULTILINE + Pattern.CASE_INSENSITIVE); Matcher additionalCopyPatternMatch = additionCopyPattern.matcher(html); String additionalLink = ""; String additionalStr = ""; String additionalhtml = ""; while (additionalCopyPatternMatch.find()) { additionalLink = additionalCopyPatternMatch.group(5).replace("\"", ""); // The link for additional copies //LOG.debug("Millennium-getItemStatusList - Group 5: '" + additionalLink + "'"); additionalStr = additionalCopyPatternMatch.group(10).trim(); additionalStr = additionalStr.replace("\"", ""); //LOG.debug("Millennium-getItemStatusList - Group 10: '" + additionalStr + "'"); String strCompare = "View additional copies or search for a specific volume/copy"; //LOG.debug("strCompare: '" + strCompare + "'"); if (additionalStr.equals(strCompare)) { LOG.debug("Millennium-getItemStatusList - Found Multiple BibInfo for Circulation"); additionalItem = true; } } if (additionalItem) { StatusString getAdditionalhtml = getItemPage(additionalLink, "Additional"); additionalStr = "additional "; if (getAdditionalhtml.recordStatus.returnStatus) { additionalhtml = getAdditionalhtml.statusValue; } } else { LOG.debug("Millennium-getItemStatusList - 'View addition copies...' string is not found!"); additionalhtml = html; } if (additionalhtml.length() > 0) { LOG.debug("Millennium-getItemStatusList - Length of " + additionalStr + "bib record html: " + additionalhtml.length()); int groupNo[]; PatternGroup iPatternGroup = new PatternGroup(); ArrayList<PatternGroup> patternGroupList = new ArrayList<PatternGroup>(); // Circulation Status /* * 10/31/2011 @ 4:39 PM - Bach Nguyen - Updated this section. Using the simplest pattern but will check on * getArrayListItemStatus function (Class) to remove * <!-- field ! --> * iPatternGroup.patternValue = "^(.*?)<!-- field % --> (.*?)<!-- field ! -->(.*?)</td></tr>$"; groupNo = new int[2]; groupNo[0] = 2; groupNo[1] = 3; iPatternGroup.groupNo = groupNo; patternGroupList.add(iPatternGroup); iPatternGroup = new PatternGroup(); // Always reset to get new item value iPatternGroup.patternValue = "^(.*?)<!-- field % --> (.*?)</td></tr>$"; groupNo = new int[1]; groupNo[0] = 2; iPatternGroup.groupNo = groupNo; patternGroupList.add(iPatternGroup); */ iPatternGroup = new PatternGroup(); // Always reset to get new item value iPatternGroup.patternValue = "^(.*?)<!-- field % -->(.*?)</td></tr>$"; groupNo = new int[1]; groupNo[0] = 2; iPatternGroup.groupNo = groupNo; patternGroupList.add(iPatternGroup); String getLibraryHas = MillenniumConfig.getLibraryHasLabel(); iPatternGroup = new PatternGroup(); // Always reset to get new item value iPatternGroup.patternValue = "^(.*?)<!-- BEGIN BIBHOLDINGSRECORDS -->(?s)(.*?)bibHoldingsLabel(.*?)(?s)" + getLibraryHas + "(.*?)bibHoldingsEntry(.*?)>(.*?)</td>$"; groupNo = new int[1]; groupNo[0] = 6; iPatternGroup.groupNo = groupNo; patternGroupList.add(iPatternGroup); StatusArrayString cirsArrayList = new StatusArrayString(); int itemProcess = 1; for (int x = 0; x < patternGroupList.size(); x++) { /* LOG.debug("Circ Pattern group [" + x + "] Pattern Value is: " + patternGroupList.get(x).patternValue); LOG.debug ("Circ Pattern group [" + x + "] GroupNo length is: " + patternGroupList.get(x).groupNo.length); for (int y=0; y < patternGroupList.get(x).groupNo.length; y++) { LOG.debug ("Circ groupNo [" + y + "] in patternGroup [" + x + "] value is: " + patternGroupList.get(x).groupNo[y]); } */ cirsArrayList = getArrayListItemStatus(patternGroupList.get(x).patternValue, additionalhtml, patternGroupList.get(x).groupNo, "Circulation"); if (cirsArrayList.recordStatus.returnStatus && cirsArrayList.itemsList.size() > 0) { break; } else if (itemProcess < patternGroupList.size()) { LOG.debug("Could not find item value for this circulation pattern. Go to next Pattern group"); } else { LOG.error("Could not find item value for this Circulation pattern."); circulationFound = false; } itemProcess++; } // Call No Status patternGroupList = new ArrayList<PatternGroup>(); /* * 10/31/2011 @ 3:45 PM - Bach Nguyen - Updated this section. Using the simplest pattern but will check on * getArrayListItemStatus function (Class) to remove * <!-- field v --> * <!-- field # --> * <!-- field y --> * iPatternGroup = new PatternGroup(); // Always reset to get new item value iPatternGroup.patternValue = "^(.*?)field C --> <a(.*?)>(.*?)</a>(.*?)<!-- field v -->(.*?)</td>$"; groupNo = new int[2]; groupNo[0] = 3; groupNo[1] = 5; iPatternGroup.groupNo = groupNo; patternGroupList.add(iPatternGroup); iPatternGroup = new PatternGroup(); // Always reset to get new item value iPatternGroup.patternValue = "^(.*?)field C -->(.*?)<!-- field v -->(.*?)</td>$"; groupNo = new int[2]; groupNo[0] = 2; groupNo[1] = 3; iPatternGroup.groupNo = groupNo; patternGroupList.add(iPatternGroup); */ iPatternGroup = new PatternGroup(); // Always reset to get new item value iPatternGroup.patternValue = "^(.*?)<!-- field C -->(.*?)</td>$"; groupNo = new int[1]; groupNo[0] = 2; iPatternGroup.groupNo = groupNo; patternGroupList.add(iPatternGroup); String getCallNo = MillenniumConfig.getCallNoLabel(); iPatternGroup = new PatternGroup(); // Always reset to get new item value iPatternGroup.patternValue = "^(.*?)<!-- BEGIN BIBHOLDINGSRECORDS -->(?s)(.*?)bibHoldingsLabel(.*?)(?s)" + getCallNo + "(.*?)bibHoldingsEntry(.*?)>(.*?)</td>$"; groupNo = new int[1]; groupNo[0] = 6; iPatternGroup.groupNo = groupNo; patternGroupList.add(iPatternGroup); StatusArrayString callNoArrayList = new StatusArrayString(); itemProcess = 1; for (int x = 0; x < patternGroupList.size(); x++) { /* LOG.debug("CallNo Pattern group [" + x + "] Pattern Value is: " + patternGroupList.get(x).patternValue); LOG.debug("CallNo Pattern group [" + x + "] GroupNo length is: " + patternGroupList.get(x).groupNo.length); for (int y=0; y < patternGroupList.get(x).groupNo.length; y++) { LOG.debug("CallNo groupNo [" + y + "] in patternGroup [" + x + "] value is: " + patternGroupList.get(x).groupNo[y]); } */ callNoArrayList = getArrayListItemStatus(patternGroupList.get(x).patternValue, additionalhtml, patternGroupList.get(x).groupNo, "Call Number"); if (callNoArrayList.recordStatus.returnStatus && callNoArrayList.itemsList.size() > 0) { break; } else if (itemProcess < patternGroupList.size()) { LOG.debug("Could not find item value for this Call No pattern. Go to next Pattern group"); } else { LOG.error("Could not find item value for this Call No pattern."); callnoFound = false; } itemProcess++; } // Location Status patternGroupList = new ArrayList<PatternGroup>(); iPatternGroup = new PatternGroup(); // Always reset to get new item value //iPatternGroup.patternValue = "^(.*?)bibItemsEntry(?s)(.*?)(?s)<td(?s)(.*?)(?s)(.*?)field 1 --> (.*?)</td>$"; iPatternGroup.patternValue = "^(?s)(.*?)<!-- field 1 -->(.*?)</td>$"; groupNo = new int[1]; groupNo[0] = 2; iPatternGroup.groupNo = groupNo; patternGroupList.add(iPatternGroup); String getLocation = MillenniumConfig.getLocationLabel(); iPatternGroup = new PatternGroup(); // Always reset to get new item value iPatternGroup.patternValue = "^(.*?)<!-- BEGIN BIBHOLDINGSRECORDS -->(?s)(.*?)bibHoldingsLabel(.*?)(?s)" + getLocation + "(.*?)bibHoldingsEntry(.*?)>(.*?)</td>$"; groupNo = new int[1]; groupNo[0] = 6; iPatternGroup.groupNo = groupNo; patternGroupList.add(iPatternGroup); StatusArrayString locationArrayList = new StatusArrayString(); itemProcess = 1; for (int x = 0; x < patternGroupList.size(); x++) { /* LOG.debug("Location Pattern group [" + x + "] Pattern Value is: " + patternGroupList.get(x).patternValue); LOG.debug("Location Pattern group [" + x + "] GroupNo length is: " + patternGroupList.get(x).groupNo.length); for (int y=0; y < patternGroupList.get(x).groupNo.length; y++) { LOG.debug("Location groupNo [" + y + "] in patternGroup [" + x + "] value is: " + patternGroupList.get(x).groupNo[y]); } */ locationArrayList = getArrayListItemStatus(patternGroupList.get(x).patternValue, additionalhtml, patternGroupList.get(x).groupNo, "Location"); if (locationArrayList.recordStatus.returnStatus && locationArrayList.itemsList.size() > 0) { break; } else if (itemProcess < patternGroupList.size()) { LOG.debug("Could not find item value for this Location pattern. Go to next Pattern group"); } else { LOG.error("Could not find item value for this Location pattern."); locationFound = false; } itemProcess++; } //LOG.debug("Circ: " + circulationFound +", CallNo: " + callnoFound + ", Location: " + locationFound); String circulationStatusString = ""; if (circulationFound && callnoFound && locationFound) { LOG.debug("Millennium-getItemStatusList - Found all pattern for Circ, CallNo and Location"); LOG.debug("Millennium-getItemStatusList (Circ, CallNo, Location) = " + "(" + cirsArrayList.itemsList.size() + ", " + callNoArrayList.itemsList.size() + ", " + locationArrayList.itemsList.size() + ")"); i = 0; //String circCheck = ""; if ((cirsArrayList.itemsList != null && callNoArrayList.itemsList != null && locationArrayList.itemsList != null) && (cirsArrayList.itemsList.size() == callNoArrayList.itemsList.size()) && (callNoArrayList.itemsList.size() == locationArrayList.itemsList.size())) { LOG.debug( "Millennium-getItemStatusList - All Array ItemStatus Size are match (Same Array Size)"); for (i = 0; i < cirsArrayList.itemsList.size(); i++) { ItemStatus itemStatus = new ItemStatus(); itemStatus.itemCirStatus = cirsArrayList.itemsList.get(i); itemStatus.itemCallNoStatus = callNoArrayList.itemsList.get(i); itemStatus.itemLocStatus = locationArrayList.itemsList.get(i); itemStatusList.add(itemStatus); } itemFound = true; i = 0; //LOG.debug("Millennium - Size of itemStatusList: " + itemStatusList.size()); while (i < itemStatusList.size()) { LOG.debug("Millennium - itemStatusList[" + i + "].Location: " + itemStatusList.get(i).itemLocStatus); LOG.debug("Millennium - itemStatusList[" + i + "].CallNo: " + itemStatusList.get(i).itemCallNoStatus); LOG.debug("Millennium - itemStatusList[" + i + "].Circulation: " + itemStatusList.get(i).itemCirStatus); i++; } } else { LOG.error("Millennium-getItemStatusList - Circ, CallNo, Location have different array size"); } if (itemFound) { iStatus.returnStatus = true; iStatus.returnMsg = "Millennium-getItemStatusList - Found all same array size for Circulation Status"; itemCirculationStatus.recordStatus = iStatus; itemCirculationStatus.itemsList = itemStatusList; } else { iStatus.returnStatus = false; iStatus.returnMsg = "Millennium-getItemStatusList - Circ, CallNo, Location have different array size"; itemCirculationStatus.recordStatus = iStatus; itemCirculationStatus.itemsList = null; } } else if (cirsArrayList.itemsList == null && callNoArrayList.itemsList == null && locationArrayList.itemsList == null) { LOG.debug("Millennium-getItemStatusList - Checking online or on ordered"); String getAuthor = ""; getAuthor = getBibDescription(html, "Author"); if (getAuthor != null && getAuthor.equals("Missing")) { getAuthor = null; } String getTitle = ""; getTitle = getBibDescription(html, "Title"); if (getTitle != null && getTitle.equals("Missing")) { getTitle = null; } String getPublisher = ""; getPublisher = getBibDescription(html, "Publisher"); if (getPublisher != null && getPublisher.equals("Missing")) { getPublisher = null; } //LOG.debug("Value for Author, Title, Publisher: " + getAuthor + ", " + getTitle + "," + getPublisher); if (getAuthor != null || getTitle != null || getPublisher != null) { if (additionalhtml.contains("class=\"bibLinks\"")) { LOG.debug("Millennium - item Status of Circulation, Location, Call No is on the web"); ItemStatus itemStatus = new ItemStatus(); itemStatus.itemCirStatus = "Available"; itemStatus.itemCallNoStatus = "Online"; itemStatus.itemLocStatus = "On the Web"; itemStatusList.add(itemStatus); iStatus.returnStatus = true; iStatus.returnMsg = "Millennium-getItemStatusList - Found Circulation Online"; itemCirculationStatus.recordStatus = iStatus; itemCirculationStatus.itemsList = itemStatusList; } else if (additionalhtml.contains("class=\"bibOrderEntry\"")) { LOG.debug( "Millennium - item Status of Circulation, Location, Call No is on ordered/processed"); ItemStatus itemStatus = new ItemStatus(); itemStatus.itemCirStatus = ""; itemStatus.itemCallNoStatus = ""; itemStatus.itemLocStatus = "Ordered/Processed"; itemStatusList.add(itemStatus); iStatus.returnStatus = true; iStatus.returnMsg = "Millennium-getItemStatusList - Found Circulation on Ordered/Processed"; itemCirculationStatus.recordStatus = iStatus; itemCirculationStatus.itemsList = itemStatusList; } else { iStatus.returnStatus = false; iStatus.returnMsg = "Millennium-getItemStatusList - Couldn't found any information for Circulation Status"; itemCirculationStatus.recordStatus = iStatus; itemCirculationStatus.itemsList = null; } } else { LOG.debug( "Millennium - The html return page does not contain any information for looking item!"); iStatus.returnStatus = false; iStatus.returnMsg = "Millennium-getItemStatusList - Couldn't found any information for Circulation Status"; itemCirculationStatus.recordStatus = iStatus; itemCirculationStatus.itemsList = null; } } else { if (circulationFound == false) circulationStatusString = "Circulation"; if (callnoFound == false) { if (circulationStatusString.length() == 0) circulationStatusString = "Call No"; else circulationStatusString = circulationStatusString + ", Call No"; } if (locationFound == false) { if (circulationStatusString.length() == 0) circulationStatusString = "Location"; else circulationStatusString = circulationStatusString + ", Location"; } LOG.error("Millennium-getItemStatusList - Couldn't find pattern for: " + circulationStatusString); iStatus.returnStatus = false; iStatus.returnMsg = "Millennium-getItemStatusList - Couldn't find pattern for: " + circulationStatusString; itemCirculationStatus.recordStatus = iStatus; itemCirculationStatus.itemsList = null; } } else { iStatus.returnStatus = false; iStatus.returnMsg = "Item bib record html is empty!"; itemCirculationStatus.recordStatus = iStatus; itemCirculationStatus.itemsList = null; } return itemCirculationStatus; }
From source file:de.undercouch.bson4jackson.BsonParser.java
/** * Converts a BSON regex pattern string to a combined value of Java flags that * can be used in {@link Pattern#compile(String, int)} * @param pattern the regex pattern string * @return the Java flags//from w ww . ja v a 2 s . com * @throws JsonParseException if the pattern string contains a unsupported flag */ protected int regexStrToFlags(String pattern) throws JsonParseException { int flags = 0; for (int i = 0; i < pattern.length(); ++i) { char c = pattern.charAt(i); switch (c) { case 'i': flags |= Pattern.CASE_INSENSITIVE; break; case 'm': flags |= Pattern.MULTILINE; break; case 's': flags |= Pattern.DOTALL; break; case 'u': flags |= Pattern.UNICODE_CASE; break; case 'l': case 'x': //unsupported break; default: throw new JsonParseException("Invalid regex", getTokenLocation()); } } return flags; }
From source file:org.jahia.services.templates.ModuleBuildHelper.java
private String getMavenError(String out) { Matcher m = Pattern.compile("^\\[ERROR\\](.*)$", Pattern.MULTILINE).matcher(out); StringBuilder s = new StringBuilder(); while (m.find()) { s.append(m.group(1)).append("\n"); }//from w w w.j av a 2 s.com return s.toString(); }
From source file:com.geecko.QuickLyric.MainActivity.java
private String getIdUrl(String extra) { final Pattern urlPattern = Pattern.compile( "(?:^|[\\W])((ht|f)tp(s?):\\/\\/|www\\.)" + "(([\\w\\-]+\\.){1,}?([\\w\\-.~]+\\/?)*" + "[\\p{Alnum}.,%_=?&#\\-+()\\[\\]\\*$~@!:/{};']*)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL); if (!(extra == null || extra.isEmpty())) { Matcher matcher = urlPattern.matcher(extra); if (matcher.find()) return extra.substring(matcher.start(), matcher.end()); }//from w w w. j a v a 2s . co m return null; }
From source file:org.geopublishing.atlasViewer.GpCoreUtil.java
/** * This method converts backslashes to forwardslashes in any html document. * Backslashes dont work in linux environments and when using the atlas out * of a .jar geopublisher expects forwardslashes * //w w w . java 2s . co m * @param url * @return */ public static URL convertWindowsToLinuxSlashesInHtmlSrcTags(URL url) { String htmlString = IOUtil.readURLasString(url); File tempFile = null; Pattern p = Pattern.compile("(<[^>]+(?:src|href)=\"[^\"]*)\\\\([^\"]*\"[^>]*>)", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(htmlString); while (m.find()) { htmlString = m.replaceAll("$1/$2"); m = p.matcher(htmlString); } try { tempFile = IOUtil.createTemporaryFile("tmp", ".html", true); InputStream bais = new ByteArrayInputStream(htmlString.getBytes()); IOUtil.writeStreamToFile(bais, tempFile); IOUtil.copyFileNoException(null, tempFile, IOUtil.urlToFile(url), false); } catch (IOException e) { } return url; }