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:com.scaniatv.LangFileUpdater.java
/** * Method that gets the ID from the custom and default lang file, and adds * missing lang IDs to the custom one, plus returns the lang ID and matches in a HashMap. * /* ww w. j ava2 s . c o m*/ * @param defaultLang * @param customLang * @return */ private static HashMap<String, String> getCustomAndDefaultLangMap(String defaultLang, String customLang) { // Create a new patter that will match if the default lang ID is also in the custom one. final Pattern pattern = Pattern.compile( "^\\$\\.lang\\.register\\((\\'|\\\")([a-zA-Z0-9,.-]+)(\\'|\\\")\\,\\s(\\'|\\\")(.*)(\\'|\\\")\\);", Pattern.MULTILINE); // Get all matches for the default lang. final Matcher m1 = pattern.matcher(defaultLang); final HashMap<String, String> defaultMatches = new HashMap<>(); while (m1.find()) { defaultMatches.put(m1.group(2), m1.group(5)); } // Get all matches for the custom lang. final Matcher m2 = pattern.matcher(customLang); final HashMap<String, String> customMatches = new HashMap<>(); while (m2.find()) { customMatches.put(m2.group(2), m2.group(5)); } // Check if any is missing in the custom one. defaultMatches.forEach((String key, String value) -> { if (!customMatches.containsKey(key)) { customMatches.put(key, value); } }); return customMatches; }
From source file:org.geotools.data.couchdb.client.CouchDBUtils.java
public static String stripComments(String json) { Pattern pat = Pattern.compile("/\\*(?:.)*?\\*/", Pattern.MULTILINE | Pattern.DOTALL); return pat.matcher(json).replaceAll(""); }
From source file:wuit.common.crawler.search.Crawler.java
public static String match(String content, String filter) { String val = ""; try {/*from ww w. jav a 2s.c o m*/ Matcher m = Pattern.compile(filter, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE).matcher(content); while (m.find()) { val = m.group(); break; } } catch (Exception e) { System.out.println("Composite Parse match " + e.getMessage()); } return val; }
From source file:org.projectforge.business.scripting.GroovyEngine.java
private String replaceIncludes(final String template) { if (template == null) { return null; }// w ww.ja va 2 s. c om final Pattern p = Pattern.compile("#INCLUDE\\{([0-9\\-\\.a-zA-Z/]*)\\}", Pattern.MULTILINE); final StringBuffer buf = new StringBuffer(); final Matcher m = p.matcher(template); while (m.find()) { if (m.group(1) != null) { final String filename = m.group(1); final Object[] res = configurationService.getResourceContentAsString(filename); String content = (String) res[0]; if (content != null) { content = replaceIncludes(content).replaceAll("\\\\", "#HURZ1#").replaceAll("\\$", "#HURZ2#"); m.appendReplacement(buf, content); // Doesn't work with '$' or '\' in content } else { m.appendReplacement(buf, "*** " + filename + " not found! ***"); } } } m.appendTail(buf); return buf.toString(); }
From source file:Normalization.TextNormalization.java
public String removeTwoLetterWordsFromString(String content) { String utf8tweet = ""; try {/*from w w w. j av a2 s .c o m*/ byte[] utf8Bytes = content.getBytes("UTF-8"); utf8tweet = new String(utf8Bytes, "UTF-8"); } catch (UnsupportedEncodingException e) { } final String regex = "((^|\\s)(\\w{1,2})(\\s|$))"; final Pattern unicodeOutliers = Pattern.compile(regex, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); Matcher unicodeOutlierMatcher = unicodeOutliers.matcher(utf8tweet); utf8tweet = unicodeOutlierMatcher.replaceAll(" "); return utf8tweet; }
From source file:nl.esciencecenter.medim.dicom.types.DicomTags.java
protected void readFromText(String txt) throws IOException { // Pass I: remove comments including the ending newline! Pattern pat = Pattern.compile("^#.*\n", Pattern.MULTILINE); String newTxt = pat.matcher(txt).replaceAll(""); // Not needed: Pass II: remove empty lines as a result of the // pat=Pattern.compile("\n\n",Pattern.MULTILINE); // newTxt=pat.matcher(newTxt).replaceAll(""); // ObjectMapper mapper=new ObjectMapper(); CsvMapper mapper = new CsvMapper(); CsvSchema schema = mapper.schemaFor(CsvTagLine.class); // create object mapping from CsvLine.class // CsvSchema schema = CsvSchema.builder() // .addColumn(CSV_GROUP) // .addColumn(CSV_ELEMENT) // .addColumn(CSV_VR) // .addColumn(CSV_NAME) // .build();/*from w w w. j a va2 s.c om*/ MappingIterator<CsvTagLine> mi = mapper.reader(CsvTagLine.class).with(schema).readValues(newTxt); List<TagDirective> tags = new ArrayList<TagDirective>(); // skip first: CsvTagLine header = mi.nextValue(); // check header values. while (mi.hasNextValue()) { CsvTagLine line = mi.nextValue(); TagDirective tag = new TagDirective(); // do something? tag.tagNr = StringUtil.parseHexidecimal(line.group) * 0x10000 + StringUtil.parseHexidecimal(line.element); tag.name = line.name; line.keep = StringUtil.stripWhiteSpace(line.keep); line.options = StringUtil.stripWhiteSpace(line.options); // Support OX if (StringUtil.equalsIgnoreCase(line.VR, "OX")) line.VR = "OB"; // treat as bytes; VRType vrType = VRType.valueOf(line.VR); tag.vr = vrType.vr(); boolean keep = false; if (StringUtil.isWhiteSpace(line.keep) == false) keep = (Integer.parseInt(line.keep) > 0); if (keep == false) { tag.option = TagProcessingOption.DELETE; } else { // check option: // System.err.printf("- %s | %s | %s | %s\n",line.group,line.element,line.keep,line.options); if (StringUtil.isWhiteSpace(line.options) == false) { tag.option = TagProcessingOption.valueOfOrNull(line.options, true); // error parsing option: if (tag.option == null) { throw new IOException("Parse Error: could not parse Tag Option:" + line.options); } } else { tag.option = TagProcessingOption.KEEP; // no option -> keep. } } tags.add(tag); } // POST: check tags: for (int i = 0; i < tags.size(); i++) { TagDirective tag = tags.get(i); // logger.debugPritnf("TagOption: 0x%8x '%s' : %s\n",tag.tagNr,tag.name,tag.option); this.dicomTags.put(tag.tagNr, tag); // register } }
From source file:net.sourceforge.jwbf.actions.mw.queries.GetCategoryMembers.java
/** * gets the information about a follow-up page from a provided api response. * If there is one, a new request is added to msgs by calling generateRequest. * /* w w w .j a v a2 s . co m*/ * @param s text for parsing */ private void parseHasMore(final String s) { // get the blcontinue-value Pattern p = Pattern.compile( "<query-continue>.*?" + "<categorymembers *cmcontinue=\"([^\"]*)\" */>" + ".*?</query-continue>", Pattern.DOTALL | Pattern.MULTILINE); Matcher m = p.matcher(s); if (m.find()) { nextPageInfo = m.group(1); } }
From source file:wuit.common.crawler.WebSit.Crawler.java
public static void matchValues(String content, String filter, List<KeyValue> list) { if (list == null) list = new ArrayList<KeyValue>(); try {/*from w ww.j av a2 s. c om*/ Matcher m = Pattern.compile(filter, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE).matcher(content); while (m.find()) { if (m.group().isEmpty()) continue; KeyValue value = new KeyValue(); value.value = m.group(); value.start = m.start(); value.end = m.end(); list.add(value); } } catch (Exception e) { System.out.println("Crawler Utitles matchValues :" + e.getMessage()); } }
From source file:com.etime.ETimeUtils.java
/** * Return a List of Punches for the current day. The list is empty if there are no punches for today. * * @param page the raw html of the user's timecard page * @return A list of Punches for the current day. *//*from ww w . j a v a2 s . c o m*/ protected static List<Punch> getTodaysPunches(String page) { String curRow; String date; List<Punch> punchesList = new LinkedList<Punch>(); Calendar calendar = Calendar.getInstance(); int month = calendar.get(Calendar.MONTH) + 1; int day = calendar.get(Calendar.DAY_OF_MONTH); String dayOfWeek = daysOfWeek[calendar.get(Calendar.DAY_OF_WEEK) - 1]; if (day < 10) { date = dayOfWeek + " " + Integer.toString(month) + "/0" + Integer.toString(day); } else { date = dayOfWeek + " " + Integer.toString(month) + "/" + Integer.toString(day); } try { Pattern todaysRowsPattern = Pattern.compile("(?i)(>" + date + ")(.*?)(</tr>)", Pattern.MULTILINE | Pattern.DOTALL); Matcher todaysRowsMatcher = todaysRowsPattern.matcher(page); while (todaysRowsMatcher.find()) { curRow = todaysRowsMatcher.group(2); addPunchesFromRowToList(curRow, punchesList); } } catch (Exception e) { Log.w(TAG, e.toString()); } return punchesList; }
From source file:com.andrada.sitracker.reader.SamlibAuthorPageReader.java
@Nullable @Override// w ww. j a v a 2 s. c o m public String getAuthorDescription() { Pattern pattern = Pattern.compile(Constants.AUTHOR_DESCRIPTION_TEXT_REGEX, Pattern.MULTILINE); Matcher matcher = pattern.matcher(pageContent); String descriptionText = null; if (matcher.find()) { descriptionText = (matcher.group(1)); } return descriptionText; }