List of usage examples for java.util.regex Pattern DOTALL
int DOTALL
To view the source code for java.util.regex Pattern DOTALL.
Click Source Link
From source file:hu.petabyte.redflags.engine.gear.parser.hu.FrameworkAgreementParser.java
@Override protected Notice processImpl(Notice notice) throws Exception { for (ObjOfTheContract obj : notice.getObjs()) { if (null != obj.getFrameworkAgreement()) { String[] p = obj.getFrameworkAgreement().split("A keretmegllapods idtartama"); if (p.length > 1) { String raw = p[1].trim().split("\n")[0]; Duration d = new Duration(); d.setRaw(raw);/* w ww.j a va2s.c o m*/ rvp.parseDuration(d); obj.setFrameworkDuration(d); } } String s = obj.getFrameworkAgreement(); if (null != s) { String regex = "Keretmegllapods (?<a>egy|tbb) ajnlattevvel(.*?(?<b>\\d+).*id)?"; Pattern p = Pattern.compile(regex, Pattern.DOTALL); Matcher m = p.matcher(s); if (m.find()) { if ("egy".equals(m.group("a"))) { obj.setFrameworkParticipants(1); } else { obj.setFrameworkParticipants(Integer.parseInt(m.group("b"))); } } } } return notice; }
From source file:com.predic8.membrane.examples.tests.LoadBalancerSession3Test.java
/** * The test as described in README.txt, but "wsimport" (previously called by ant) * was removed and is run directly from this test before everything else. Thereby * we can use a Maven dependency on wsimport and do not have to download it ourselves. *//*from w w w .j ava 2s . co m*/ @Test public void test() throws IOException, InterruptedException { File base = getExampleDir("loadbalancer-session-3"); AssertUtils.replaceInFile(new File(base, "proxies.xml"), "8080", "3023"); AssertUtils.replaceInFile(new File(base, "src/com/predic8/chat/Client.java"), "8080", "3023"); AssertUtils.replaceInFile(new File(base, "data/ChatService.wsdl"), "8080", "3023"); Process2 sl = new Process2.Builder().in(base).script("service-proxy").waitForMembrane().start(); try { File buildXML = new File(base, "build.xml"); // remove <exec...</exec> from build.xml String s = Pattern.compile("<exec.*</exec>", Pattern.DOTALL) .matcher(FileUtils.readFileToString(buildXML)).replaceAll(""); FileUtils.writeStringToFile(buildXML, s); File classes = new File(base, "build" + File.separator + "classes"); classes.mkdirs(); File source = new File(base, "src"); source.mkdirs(); // run "wsimport" generating java sources Assert.assertTrue(new com.sun.tools.ws.wscompile.WsimportTool(System.out).run(new String[] { "-quiet", "-Xnocompile", new File(base, "data" + File.separator + "ChatService.wsdl").getAbsolutePath(), "-s", source.getAbsolutePath() })); // call "ant compile" now so that both antNodeX processes do call it at the same time BufferLogger loggerCompile = new BufferLogger(); Process2 antCompile = new Process2.Builder().in(base).withWatcher(loggerCompile) .executable("ant compile").start(); try { int result = antCompile.waitFor(60000); if (result != 0) throw new AssertionError( "'ant compile' returned non-zero " + result + ":\r\n" + loggerCompile.toString()); } finally { antCompile.killScript(); } BufferLogger loggerNode1 = new BufferLogger(); BufferLogger loggerNode2 = new BufferLogger(); Process2 antNode1 = new Process2.Builder().in(base).withWatcher(loggerNode1).executable("ant run-node1") .start(); try { Process2 antNode2 = new Process2.Builder().in(base).withWatcher(loggerNode2) .executable("ant run-node2").start(); try { LoadBalancerUtil.addLBNodeViaHTML("http://localhost:9000/admin/", "localhost", 4000); LoadBalancerUtil.addLBNodeViaHTML("http://localhost:9000/admin/", "localhost", 4001); Thread.sleep(1000); // wait for nodes to come up Process2 antClient = new Process2.Builder().in(base).executable("ant run-client -Dlogin=jim") .start(); try { antClient.waitFor(60000); } finally { antClient.killScript(); } } finally { antNode2.killScript(); } } finally { antNode1.killScript(); } AssertUtils.assertContains("Hallo World", loggerNode1.toString()); AssertUtils.assertContainsNot("Hallo World", loggerNode2.toString()); } finally { sl.killScript(); } }
From source file:net.rptools.maptool.client.functions.StrListFunctions.java
/** * Parses a list./*from w w w . j a v a 2 s. c o m*/ * * @param listStr * has the form "item1, item2, ..." * @param list * is populated with the list items. * @param delim * is the list delimiter to use. */ public static void parse(String listStr, List<String> list, String delim) { if (StringUtils.isEmpty(listStr.trim())) return; // null strings have zero entries String patt; if (delim.equalsIgnoreCase("")) { patt = "(.)()"; } else { String escDelim = fullyQuoteString(delim); patt = "(.*?)" + escDelim + "|(.*)"; } // This pattern needs to be compiled with the DOTALL flag or line terminators might // cause premature termination of the matcher.find() operations... Pattern pattern = Pattern.compile(patt, Pattern.DOTALL); Matcher matcher = pattern.matcher(listStr); boolean lastItem = false; while (matcher.find()) { if (!lastItem) { String grp = matcher.group(1); if (grp == null) { grp = matcher.group(2); // We're here because there was no trailing delimiter in this match. // In this case, the next match will be empty, but we don't want to grab it. // (We do grab the final empty match if the string ended with the delimiter.) // This flag will prevent that. lastItem = true; } list.add(grp.trim()); } } }
From source file:org.rifidi.emulator.reader.thingmagic.commandobjects.CloseCommand.java
public CloseCommand(String command, ThingMagicReaderSharedResources tmsr) throws CommandCreationException { this.tmsr = tmsr; this.command = command; List<String> tokens = new ArrayList<String>(); /*//w w w . j a v a 2 s.com * This regex looks for a Word, or a series of spaces on either side of * any single comparison operator or comma, or a single parentheses * (opening or closing). At the last ... any dangling spaces not * attached to the above groups and then anything else as a single * group. * * This makes it really easy to parse the command string as it becomes * really predictable tokens. */ Pattern tokenizer = Pattern.compile( // anything less... "[^\\s\\w]+|" + // groups we are looking for... "\\w+|" + "\\s+", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); Matcher tokenFinder = tokenizer.matcher(command.toLowerCase().trim()); while (tokenFinder.find()) { String temp = tokenFinder.group(); /* * no need to add empty strings at tokens. */ // TODO: Figure out why we are getting empty stings as tokens. if (temp.equals("")) continue; tokens.add(temp); } ListIterator<String> tokenIterator = tokens.listIterator(); String token = tokenIterator.next(); if (!token.equals("close")) throw new CommandCreationException("Error 0100: syntax error at '" + token + "'"); try { token = tokenIterator.next(); if (!token.matches(WHITE_SPACE)) throw new CommandCreationException("Error 0100: syntax error at '" + token + "'"); token = tokenIterator.next(); if (token.matches(A_WORD)) { cursorName = token; logger.debug("Cursor name is " + cursorName); } else { throw new CommandCreationException("Error 0100: syntax error at '" + token + "'"); } // check if the command correctly ends in a semicolon if (tokenIterator.hasNext()) { token = tokenIterator.next(); if (token.matches(WHITE_SPACE)) { token = tokenIterator.next(); } if (!token.equals(";")) { throw new CommandCreationException("Error 0100: syntax error at '" + token + "'"); } } else { throw new CommandCreationException("Error 0100: syntax error at '\n'"); } } catch (NoSuchElementException e) { /* * if we get here... we run out of tokens prematurely... Our job now * is to walk backwards to find the last non space tokens and throw * an exception saying that there is an syntax error at that point. */ /* * look for the last offending command block that is not a series of * whitespaces. */ token = tokenIterator.previous(); while (token.matches(WHITE_SPACE)) { token = tokenIterator.previous(); } logger.debug("Premature end of token list detected."); throw new CommandCreationException("Error 0100: syntax error at '" + token + "'"); } if (!tmsr.getCursorCommandRegistry().containsKey(cursorName)) { throw new CommandCreationException("Error 0100: DELETE: Cursor does not exist\n"); } }
From source file:com.redhat.lightblue.eval.RegexEvaluator.java
/** * Constructs evaluator for {field op value} style comparison * * @param expr The expression// w ww. ja va2 s. com * @param md Entity metadata * @param context The path relative to which the expression will be * evaluated */ public RegexEvaluator(RegexMatchExpression expr, FieldTreeNode context) { this.relativePath = expr.getField(); fieldMd = context.resolve(relativePath); if (fieldMd == null) { throw new EvaluationError(expr, CrudConstants.ERR_FIELD_NOT_THERE + relativePath); } int flags = 0; if (expr.isCaseInsensitive()) { flags |= Pattern.CASE_INSENSITIVE; } if (expr.isMultiline()) { flags |= Pattern.MULTILINE; } if (expr.isExtended()) { flags |= Pattern.COMMENTS; } if (expr.isDotAll()) { flags |= Pattern.DOTALL; } regex = Pattern.compile(expr.getRegex(), flags); LOGGER.debug("ctor {} {}", relativePath, regex); }
From source file:io.github.chrisbotcom.reminder.CommandParser.java
public CommandParser(Reminder plugin) { this.plugin = plugin; // Compile regex pattern String commands = "add|list|delete|del|update|up|reload|stop|resume|start|time|setdefault|setdefaults|set|upgrade"; String tags = "tag|delay|rate|echo"; String cmd = String.format("(?<cmd>^%s)", commands); String id = "(?:\\s+)(?<id>\\d+)"; String tag = String.format("(?:\\s+)(?<tag>%s)(?:\\s+)(?<value>\\w+)", tags); String date = "(?:\\s+)(?<date>\\d{1,4}-\\d{1,2}-\\d{1,2})"; String time = "(?:\\s+)(?<time>\\d{1,2}:\\d{2})"; String offset = "(?:\\s+)(?<offset>\\+\\d+)"; String msg = "(?:\\s+)(?:[\\\"\\'])(?<msg>.*?)(?:[\\\"\\'])"; String player = "(?:\\s+)(?<player>\\w+|\\*)"; pattern = Pattern.compile(/*from www . ja v a2 s .c o m*/ String.format("%s|%s|%s|%s|%s|%s|%s|%s", cmd, tag, date, time, offset, id, msg, player), Pattern.CASE_INSENSITIVE | Pattern.DOTALL); }
From source file:util.RegexStrUtil.java
static boolean hasHTML(String body) { if (!RegexStrUtil.isNull(body)) { Pattern pattern = Pattern.compile("<.*?>", Pattern.DOTALL); Matcher matcher = pattern.matcher(body); return matcher.find(); }/* www . j a va2 s . c om*/ return false; }
From source file:org.xwiki.rendering.internal.docbook.DocBookParserTest.java
@Ignore("Ignored till we fix the DocBook parser to make it pass!") @Test/*from ww w . ja va 2 s .c o m*/ public void parseDocbookExample() throws Exception { Parser parser = getComponentManager().getInstance(Parser.class, "docbook/4.4"); XDOM xdom = parser.parse(new InputStreamReader(getClass().getResourceAsStream("/docbook/example.xml"))); BlockRenderer renderer = getComponentManager().getInstance(BlockRenderer.class, "event/1.0"); DefaultWikiPrinter printer = new DefaultWikiPrinter(); renderer.render(xdom, printer); // Read expected content and remove license header for comparison. String expected = IOUtils.toString(getClass().getResourceAsStream("/docbook/expected.txt")); Pattern pattern = Pattern.compile("====.*====\n\n", Pattern.DOTALL); expected = pattern.matcher(expected).replaceFirst(""); Assert.assertEquals(expected, printer.toString()); }
From source file:org.goko.core.gcode.rs274ngcv3.parser.GCodeLexer.java
/** * Constructor// ww w .j a v a 2s .com */ public GCodeLexer() { multilineCommentPattern = Pattern.compile(GCodeTokenType.MULTILINE_COMMENT.getPattern(), Pattern.MULTILINE | Pattern.DOTALL); simpleCommentPattern = Pattern.compile(GCodeTokenType.SIMPLE_COMMENT.getPattern()); lineNumberPattern = Pattern.compile(GCodeTokenType.LINE_NUMBER.getPattern()); wordPattern = Pattern.compile(GCodeTokenType.WORD.getPattern()); spacePattern = Pattern.compile("^[ ]+"); percentPattern = Pattern.compile(GCodeTokenType.PERCENT.getPattern()); }
From source file:com.romeikat.datamessie.core.processing.service.fulltext.query.QueryUtil.java
public FullTextQuery parseQuery(final String luceneQueryString, final Analyzer analyzer) { LOG.debug("Parsing query: {}", luceneQueryString); // Check if query is "n outof abc def ghi" final Pattern pattern = Pattern.compile("\\s*(\\d+)\\s+outof\\s+(.*)", Pattern.DOTALL | Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); final Matcher matcher = pattern.matcher(luceneQueryString); // Match => OUTOF query if (matcher.matches()) { final int k = Integer.parseInt(matcher.group(1)); final String searchString = matcher.group(2); final List<String> queryTerms = parseUtil.parseTerms(searchString, analyzer, true); final OutOfQuery query = new OutOfQuery(k, queryTerms); LOG.debug("Detected {}", query); return query; }/*from w w w. j a v a 2s. c o m*/ // No match => Lucene query else { final LuceneQuery query = new LuceneQuery(luceneQueryString); LOG.debug("Detected {}", query); return query; } }