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:org.openmrs.module.rheapocadapter.util.GetPatientUtil.java
public String[] getHL7FromPipeString(String theSource) { ArrayList<String> messages = new ArrayList<String>(20); Pattern startPattern = Pattern.compile("^MSH", Pattern.MULTILINE); Matcher startMatcher = startPattern.matcher(theSource); while (startMatcher.find()) { String messageExtent = getMessageExtent(theSource.substring(startMatcher.start()), startPattern); char fieldDelim = messageExtent.charAt(3); Pattern segmentPattern = Pattern.compile("^[A-Z\\d]{3}\\" + fieldDelim + ".*$", Pattern.MULTILINE); Matcher segmentMatcher = segmentPattern.matcher(messageExtent); StringBuffer msg = new StringBuffer(); while (segmentMatcher.find()) { msg.append(segmentMatcher.group().trim()); msg.append('\r'); }// w w w . ja v a 2s. c o m messages.add(msg.toString()); } return messages.toArray(new String[0]); }
From source file:org.mili.ant.PropertiesReplacerImpl.java
private String replace(String rep, String data) { String what = actuals.what.getContent(); if (actuals.replace.isRegexp()) { rep = rep.replace("$", "\\$"); Matcher m = Pattern.compile(what, Pattern.MULTILINE).matcher(data); if (m.find()) { data = m.replaceAll(rep);/*from www . java 2 s. c o m*/ } else if (actuals.replaceFile.isHaltOnError()) { throwNothingToReplaceException(); } } else { int index = data.indexOf(what); if (index >= 0) { data = data.replace(what, rep); } else if (index < 0 && actuals.replaceFile.isHaltOnError()) { throwNothingToReplaceException(); } } return data; }
From source file:com.openedit.util.URLUtilities.java
public static String escapeUtf8(String inCode) { if (VALIDUTF8 == null) { VALIDUTF8 = Pattern.compile("[^\\u0009\\u000a\\u000d\\u0020-\\uD7FF\\uE000-\\uFFFD]", Pattern.MULTILINE); }/*from w w w . j a v a2s. c o m*/ String clean = VALIDUTF8.matcher(inCode).replaceAll(""); return clean; //s/.*?((?:[\t\n\r\x20-\x7E])+|(?:\xD0[\x90-\xBF])+|(?:\xD1[\x80-\x8F])+|(?:\xC3[\x80-\xBF])+|).*?/$1/sg; }
From source file:org.csanchez.jenkins.plugins.kubernetes.pipeline.ContainerExecDecoratorTest.java
@Test public void testCommandExecutionWithEscaping() throws Exception { ProcReturn r = execCommand(false, "sh", "-c", "cd /tmp; false; echo result is $$? > test; cat /tmp/test"); assertTrue("Output should contain result: " + r.output, Pattern.compile("^(result is 1)$", Pattern.MULTILINE).matcher(r.output).find()); assertEquals(0, r.exitCode);/*from w w w . j a v a2 s.co m*/ assertFalse(r.proc.isAlive()); }
From source file:io.selendroid.android.impl.AbstractDevice.java
protected static String extractValue(String regex, String output) { Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); Matcher matcher = pattern.matcher(output); if (matcher.find()) { return matcher.group(1); }//from w w w.ja v a2s .c o m return ""; }
From source file:amp.lib.io.db.SQLFactory.java
/** * Simplifies an every complex SQL error message. * @param message the message//from w w w. ja v a 2s .c o m * @return the simplified message */ public String simplifyErrorMessage(String message) { Pattern p = Pattern.compile("MESSAGE: *(.*\\n)", Pattern.MULTILINE); Matcher m = p.matcher(message); if (m.find() && m.groupCount() > 0) { message = m.group(1); } return message; }
From source file:dk.dma.msinm.web.rest.LocationRestService.java
/** * Annoyingly, different versions of KML use different default namespaces. * Hence, attempt to extract the default namespace * @param kml the xml/* w ww . j a v a2 s .c o m*/ * @return the default KML namespace */ private String extractDefaultNamespace(String kml) { Pattern p = Pattern.compile(".*<kml xmlns=\"([^\"]*)\".*", Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE); Matcher m = p.matcher(kml); if (m.matches()) { return m.group(1); } return "http://www.opengis.net/kml/2.2"; }
From source file:org.squale.welcom.struts.lazyLoading.WLazyUtil.java
/** * pure le corps d'une page// w w w. j ava 2s. c o m * * @param corps chaine contenant le flux modifier * @return le flux modifi */ public static String getLightBody(final String corps) { final StringBuffer buf = new StringBuffer(); // try { // Cherche les inputs Pattern reg = Pattern.compile("(<\\s*input[^>]*>)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); Matcher mat = reg.matcher(corps); // RE reg=new RE("(<\\s*input[^>]*>)",RE.MATCH_CASEINDEPENDENT); int pos = 0; while (mat.find(pos)) { buf.append(convertInputToLightInput(mat.group(0))); pos = mat.end(0); } // Cherche les textarea reg = Pattern.compile("(<\\s*textarea[^>]*>[^<]*<\\/\\s*textarea\\s*>)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); mat = reg.matcher(corps); // reg=new RE("(<\\s*textarea[^>]*>[^<]*<\\/\\s*textarea\\s*>)",RE.MATCH_CASEINDEPENDENT); pos = 0; while (mat.find(pos)) { buf.append(mat.group(0)); pos = mat.end(0); } // cherche les selects // RE regstart=new RE("(<select)",RE.MATCH_CASEINDEPENDENT); final Pattern regstart = Pattern.compile("(<\\s*select)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); // RE regstop=new RE("(</select>)",RE.MATCH_CASEINDEPENDENT); final Pattern regstop = Pattern.compile("(<\\s*/select>\\s*)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); final Matcher mastart = regstart.matcher(corps); final Matcher mastop = regstop.matcher(corps); pos = 0; while (mastart.find(pos)) { final int posStart = mastart.start(1); int posStop = mastart.end(1); if (mastop.find(posStart)) { posStop = mastop.end(1); final String value = corps.substring(posStart, posStop); buf.append(convertSelectToLightInput(value)); } pos = posStop; } return buf.toString(); }
From source file:org.sonar.dotnet.tools.commons.visualstudio.ModelFactory.java
/** * Gets all the projects in a solution./*from www . j a v a2 s . c o m*/ * * @param solutionFile * the solution file * @param solutionContent * the text content of the solution file * @return a list of projects * @throws IOException * @throws DotNetToolsException */ private static List<VisualStudioProject> getProjects(File solutionFile, String solutionContent, List<String> buildConfigurations) throws IOException, DotNetToolsException { File baseDirectory = solutionFile.getParentFile(); // A pattern to extract the projects from a visual studion solution String projectExtractExp = "(Project.*?^EndProject$)"; Pattern projectExtractPattern = Pattern.compile(projectExtractExp, Pattern.MULTILINE + Pattern.DOTALL); List<String> projectDefinitions = new ArrayList<String>(); // Extracts all the projects from the solution Matcher globalMatcher = projectExtractPattern.matcher(solutionContent); while (globalMatcher.find()) { String projectDefinition = globalMatcher.group(1); projectDefinitions.add(projectDefinition); } // This pattern extracts the projects from a Visual Studio solution String normalProjectExp = "\\s*Project\\([^\\)]*\\)\\s*=\\s*\"([^\"]*)\"\\s*,\\s*\"([^\"]*?\\.csproj)\""; String webProjectExp = "\\s*Project\\([^\\)]*\\)\\s*=\\s*\"([^\"]*).*?ProjectSection\\(WebsiteProperties\\).*?" + "Debug\\.AspNetCompiler\\.PhysicalPath\\s*=\\s*\"([^\"]*)"; Pattern projectPattern = Pattern.compile(normalProjectExp); Pattern webPattern = Pattern.compile(webProjectExp, Pattern.MULTILINE + Pattern.DOTALL); List<VisualStudioProject> result = new ArrayList<VisualStudioProject>(); for (String projectDefinition : projectDefinitions) { // Looks for project files Matcher matcher = projectPattern.matcher(projectDefinition); if (matcher.find()) { String projectName = matcher.group(1); String projectPath = StringUtils.replace(matcher.group(2), "\\", File.separatorChar + ""); File projectFile = new File(baseDirectory, projectPath); if (!projectFile.exists()) { throw new FileNotFoundException("Could not find the project file: " + projectFile); } VisualStudioProject project = getProject(projectFile, projectName, buildConfigurations); result.add(project); } else { // Searches the web project Matcher webMatcher = webPattern.matcher(projectDefinition); if (webMatcher.find()) { String projectName = webMatcher.group(1); String projectPath = webMatcher.group(2); if (projectPath.endsWith("\\")) { projectPath = StringUtils.chop(projectPath); } File projectRoot = new File(baseDirectory, projectPath); VisualStudioProject project = getWebProject(baseDirectory, projectRoot, projectName, projectDefinition); result.add(project); } } } return result; }
From source file:com.g3net.tool.StringUtils.java
/** * ???//from w w w. j a va2s .c om * * @param src * @param regexp * @param ignoreCase * @param startPos * ?? * @return */ public static boolean endsWith(String src, String regexp, boolean ignoreCase, TInteger startPos) { Pattern p = null; if (ignoreCase) { p = Pattern.compile(regexp + "$", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); } else { p = Pattern.compile(regexp + "$", Pattern.MULTILINE); } Matcher m = p.matcher(src); while (m.find()) { // log.info(m.group()+":"+m.start()+":"+m.end()); startPos.setValue(m.start()); return true; } return false; }