org.apache.commons.lang3.RegExUtils Java Examples
The following examples show how to use
org.apache.commons.lang3.RegExUtils.
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: RssFeed.java From torrssen2 with MIT License | 6 votes |
public void setRssTitleByTitle(String title) { Pattern pattern = Pattern.compile(".*(e\\d{2,}).*", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(title); String rssTitle = title; if (matcher.matches()) { rssTitle = rssTitle.substring(0, matcher.start(1)).replaceAll("\\.", ""); } // pattern = Pattern.compile("\\d{1,}-\\d{1,}회 합본"); pattern = Pattern.compile("E{0,1}\\d{1,}.{0,1}E{0,1}\\d{1,}회.{0,1}합본"); rssTitle = RegExUtils.removeAll(rssTitle, pattern); pattern = Pattern.compile("\\[[^\\]]{1,}\\]"); rssTitle = RegExUtils.removeAll(rssTitle, pattern); this.rssTitle = StringUtils.trim(rssTitle); }
Example #2
Source File: ScooldUtils.java From scoold with Apache License 2.0 | 6 votes |
public String sanitizeQueryString(String query, HttpServletRequest req) { String qf = getSpaceFilteredQuery(req); String defaultQuery = "*"; String q = StringUtils.trimToEmpty(query); if (qf.isEmpty() || qf.length() > 1) { q = q.replaceAll("[\\*\\?]", "").trim(); q = RegExUtils.removeAll(q, "AND"); q = RegExUtils.removeAll(q, "OR"); q = RegExUtils.removeAll(q, "NOT"); q = q.trim(); defaultQuery = ""; } if (qf.isEmpty()) { return defaultQuery; } else if ("*".equals(qf)) { return q; } else { if (q.isEmpty()) { return qf; } else { return qf + " AND " + q; } } }
Example #3
Source File: GeoIPServiceImpl.java From entrada with GNU General Public License v3.0 | 6 votes |
public boolean download(String database, String url, int timeout) { // do not log api key String logUrl = RegExUtils.removePattern(url, "&license_key=.+"); Optional<byte[]> data = DownloadUtil.getAsBytes(url, logUrl, timeout); if (data.isPresent()) { InputStream is = new ByteArrayInputStream(data.get()); try { extractDatabase(is, database); } catch (IOException e) { log.error("Error while extracting {}", database, e); return false; } return true; } // no data could be downloaded return false; }
Example #4
Source File: EclipseMavenParser.java From analysis-model with MIT License | 6 votes |
@Override protected Optional<Issue> createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { builder.guessSeverity(matcher.group("severity")) .setFileName(matcher.group("file")) .setLineStart(matcher.group("line")); String message = matcher.group("message"); if (StringUtils.isNotBlank(message)) { // single line format builder.setMessage(message); extractCategory(builder, message); } else { // multi line format List<String> code = new ArrayList<>(); while (lookahead.hasNext("^\\t.*$") && lookahead.hasNext()) { code.add(lookahead.next()); } builder.setAdditionalProperties(code.hashCode()); if (lookahead.hasNext()) { extractMessage(builder, RegExUtils.removeFirst(lookahead.next(), ".*\\t")); } } return builder.buildOptional(); }
Example #5
Source File: GeneratorController.java From FEBS-Cloud with Apache License 2.0 | 5 votes |
@PostMapping @PreAuthorize("hasAuthority('gen:generate:gen')") public void generate(@NotBlank(message = "{required}") String name, @NotBlank(message = "{required}") String datasource, String remark, HttpServletResponse response) throws Exception { GeneratorConfig generatorConfig = generatorConfigService.findGeneratorConfig(); if (generatorConfig == null) { throw new FebsException("代码生成配置为空"); } String className = name; if (GeneratorConfig.TRIM_YES.equals(generatorConfig.getIsTrim())) { className = RegExUtils.replaceFirst(name, generatorConfig.getTrimValue(), StringUtils.EMPTY); } generatorConfig.setTableName(name); generatorConfig.setClassName(FebsUtil.underscoreToCamel(className)); generatorConfig.setTableComment(remark); // 生成代码到临时目录 List<Column> columns = generatorService.getColumns(GeneratorConstant.DATABASE_TYPE, datasource, name); generatorHelper.generateEntityFile(columns, generatorConfig); generatorHelper.generateMapperFile(columns, generatorConfig); generatorHelper.generateMapperXmlFile(columns, generatorConfig); generatorHelper.generateServiceFile(columns, generatorConfig); generatorHelper.generateServiceImplFile(columns, generatorConfig); generatorHelper.generateControllerFile(columns, generatorConfig); // 打包 String zipFile = System.currentTimeMillis() + SUFFIX; FileUtil.compress(GeneratorConstant.TEMP_PATH + "src", zipFile); // 下载 FileUtil.download(zipFile, name + SUFFIX, true, response); // 删除临时目录 FileUtil.delete(GeneratorConstant.TEMP_PATH); }
Example #6
Source File: InitialSetupTask.java From genie with Apache License 2.0 | 5 votes |
/** * Helper to convert a set of tags into a string that is a suitable value for a shell environment variable. * Adds double quotes as necessary (i.e. in case of spaces, newlines), performs escaping of in-tag quotes. * Input tags are sorted to produce a deterministic output value. * * @param tags a set of tags or null * @return a CSV string */ @VisibleForTesting String tagsToString(final Set<String> tags) { final ArrayList<String> sortedTags = new ArrayList<>(tags == null ? Collections.emptySet() : tags); // Sort tags for the sake of determinism (e.g., tests) sortedTags.sort(Comparator.naturalOrder()); final String joinedString = StringUtils.join(sortedTags, ','); // Escape quotes return RegExUtils.replaceAll(RegExUtils.replaceAll(joinedString, "\'", "\\\'"), "\"", "\\\""); }
Example #7
Source File: JobResolverServiceImpl.java From genie with Apache License 2.0 | 5 votes |
/** * Helper to convert a set of tags into a string that is a suitable value for a shell environment variable. * Adds double quotes as necessary (i.e. in case of spaces, newlines), performs escaping of in-tag quotes. * Input tags are sorted to produce a deterministic output value. * * @param tags a set of tags or null * @return a CSV string */ private String tagsToString(final Set<String> tags) { final List<String> sortedTags = Lists.newArrayList(tags); // Sort tags for the sake of determinism (e.g., tests) sortedTags.sort(Comparator.naturalOrder()); final String joinedString = StringUtils.join(sortedTags, ','); // Escape quotes return RegExUtils.replaceAll(RegExUtils.replaceAll(joinedString, "'", "\\'"), "\"", "\\\""); }
Example #8
Source File: StringReplaceAndRemoveUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenTestStrings_whenReplaceExactWordUsingRegExUtilsMethod_thenProcessedString() { String sentence = "A car is not the same as a carriage, and some planes can carry cars inside them!"; String regexTarget = "\\bcar\\b"; String exactWordReplaced = RegExUtils.replaceAll(sentence, regexTarget, "truck"); assertTrue("A truck is not the same as a carriage, and some planes can carry cars inside them!".equals(exactWordReplaced)); }
Example #9
Source File: PipelineLabel.java From gocd with Apache License 2.0 | 5 votes |
public static String migratePipelineLabelTemplate(String labelTemplate) { Matcher matcher = PIPELINE_LABEL_TEMPLATE_PATTERN_FOR_MIGRATION.matcher(labelTemplate); while (matcher.find()) { String group = matcher.group(1); if (!StringUtils.startsWith(group, "${env:")) { String replacementText = RegExUtils.replaceFirst(group, "(?<!\\[):", "_"); labelTemplate = labelTemplate.replace(group, replacementText); } } return labelTemplate; }
Example #10
Source File: EventUtil.java From alf.io with GNU General Public License v3.0 | 5 votes |
public static Optional<byte[]> getIcalForEvent(Event event, TicketCategory ticketCategory, String description, Organization organization) { ICalendar ical = new ICalendar(); ical.setProductId("-//Alf.io//Alf.io v2.0//EN"); ical.setMethod(Method.PUBLISH); VEvent vEvent = new VEvent(); vEvent.setSummary(event.getDisplayName()); vEvent.setDescription(description); vEvent.setLocation(RegExUtils.replacePattern(event.getLocation(), "[\n\r\t]+", " ")); ZonedDateTime begin = Optional.ofNullable(ticketCategory).map(tc -> tc.getTicketValidityStart(event.getZoneId())).orElse(event.getBegin()); ZonedDateTime end = Optional.ofNullable(ticketCategory).map(tc -> tc.getTicketValidityEnd(event.getZoneId())).orElse(event.getEnd()); vEvent.setDateStart(Date.from(begin.toInstant())); vEvent.setDateEnd(Date.from(end.toInstant())); vEvent.setUrl(event.getWebsiteUrl()); vEvent.setStatus(Status.confirmed()); if(organization != null) { vEvent.setOrganizer(new Organizer(organization.getName(), organization.getEmail())); } ical.addEvent(vEvent); StringWriter strWriter = new StringWriter(); try (ICalWriter writer = new ICalWriter(strWriter, ICalVersion.V2_0)) { writer.write(ical); return Optional.of(strWriter.toString().getBytes(StandardCharsets.UTF_8)); } catch (IOException e) { log.warn("was not able to generate iCal for event " + event.getShortName(), e); return Optional.empty(); } }
Example #11
Source File: TotpUtils.java From mangooio with Apache License 2.0 | 5 votes |
/** * Generates a otpauth code to share a secret with a user * * @param name The name of the account * @param issuer The name of the issuer * @param secret The secret to use * @param algorithm The algorithm to use * @param digits The number of digits to use * @param period The period to use * * @return An otpauth url */ public static String getOtpauthURL(String name, String issuer, String secret, HmacShaAlgorithm algorithm, String digits, String period) { Objects.requireNonNull(name, Required.ACCOUNT_NAME.toString()); Objects.requireNonNull(secret, Required.SECRET.toString()); Objects.requireNonNull(issuer, Required.ISSUER.toString()); Objects.requireNonNull(algorithm, Required.ALGORITHM.toString()); Objects.requireNonNull(digits, Required.DIGITS.toString()); Objects.requireNonNull(period, Required.PERIOD.toString()); var buffer = new StringBuilder(); buffer.append("otpauth://totp/") .append(name) .append("?secret=") .append(RegExUtils.replaceAll(base32.encodeAsString(secret.getBytes(StandardCharsets.UTF_8)), "=", "")) .append("&algorithm=") .append(algorithm.getAlgorithm()) .append("&issuer=") .append(issuer) .append("&digits=") .append(digits) .append("&period=") .append(period); String url = ""; try { url = URLEncoder.encode(buffer.toString(), StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { LOG.error("Failed to encode otpauth url", e); } return url; }
Example #12
Source File: TappedOutDeckSniffer.java From MtgDesktopCompanion with GNU General Public License v3.0 | 5 votes |
public List<RetrievableDeck> getDeckList() throws IOException { if(httpclient==null) initConnexion(); String tappedJson = RegExUtils.replaceAll(getString(URL_JSON), "%FORMAT%", getString(FORMAT)); logger.debug("sniff url : " + tappedJson); String responseBody = httpclient.doGet(tappedJson); JsonElement root = URLTools.toJson(responseBody); List<RetrievableDeck> list = new ArrayList<>(); for (int i = 0; i < root.getAsJsonArray().size(); i++) { JsonObject obj = root.getAsJsonArray().get(i).getAsJsonObject(); RetrievableDeck deck = new RetrievableDeck(); deck.setName(obj.get("name").getAsString()); try { URI u = new URI(obj.get("resource_uri").getAsString()); deck.setUrl(u); } catch (URISyntaxException e) { deck.setUrl(null); } deck.setAuthor(obj.get("user").getAsString()); deck.setColor(""); list.add(deck); } return list; }
Example #13
Source File: ContentFeedController.java From halo with GNU General Public License v3.0 | 5 votes |
/** * Build category posts. * * @param pageable pageable must not be null. * @param category category * @return list of post detail vo. */ private List<PostDetailVO> buildCategoryPosts(@NonNull Pageable pageable, @NonNull CategoryDTO category) { Assert.notNull(pageable, "Pageable must not be null"); Assert.notNull(category, "Category slug must not be null"); Page<Post> postPage = postCategoryService.pagePostBy(category.getId(), PostStatus.PUBLISHED, pageable); Page<PostDetailVO> posts = postService.convertToDetailVo(postPage); posts.getContent().forEach(postDetailVO -> { postDetailVO.setFormatContent(RegExUtils.replaceAll(postDetailVO.getFormatContent(), XML_INVAID_CHAR, "")); postDetailVO.setSummary(RegExUtils.replaceAll(postDetailVO.getSummary(), XML_INVAID_CHAR, "")); }); return posts.getContent(); }
Example #14
Source File: ContentFeedController.java From halo with GNU General Public License v3.0 | 5 votes |
/** * Build posts. * * @param pageable pageable * @return list of post detail vo */ private List<PostDetailVO> buildPosts(@NonNull Pageable pageable) { Assert.notNull(pageable, "Pageable must not be null"); Page<Post> postPage = postService.pageBy(PostStatus.PUBLISHED, pageable); Page<PostDetailVO> posts = postService.convertToDetailVo(postPage); posts.getContent().forEach(postDetailVO -> { postDetailVO.setFormatContent(RegExUtils.replaceAll(postDetailVO.getFormatContent(), XML_INVAID_CHAR, "")); postDetailVO.setSummary(RegExUtils.replaceAll(postDetailVO.getSummary(), XML_INVAID_CHAR, "")); }); return posts.getContent(); }
Example #15
Source File: MTGoldFishDashBoard.java From MtgDesktopCompanion with GNU General Public License v3.0 | 4 votes |
private void parsing(Document d, HistoryPrice<?> historyPrice) { Element js = null; for(Element j : d.getElementsByTag("script")) { if(j.toString().contains("var d = ")) { js=j; break; } } if(js==null) { return; } AstNode root = new Parser().parse(js.html(), "", 1); isPaperparsing=true; root.visit(visitedNode -> { boolean stop = false; if (!stop && visitedNode.toSource().startsWith("d")) { String val = visitedNode.toSource(); if(val.startsWith("document.getElementById")) isPaperparsing=false; val = RegExUtils.replaceAll(val, "d \\+\\= ", ""); val = RegExUtils.replaceAll(val, "\\\\n", ""); val = RegExUtils.replaceAll(val, ";", ""); val = RegExUtils.replaceAll(val, "\"", ""); String[] res = val.split(","); try { Date date = new SimpleDateFormat("yyyy-MM-dd hh:mm").parse(res[0] + " 00:00"); if (historyPrice.get(date) == null) { if(getString(FORMAT).equals("paper") && isPaperparsing) historyPrice.put(date, Double.parseDouble(res[1])); if(getString(FORMAT).equals("online") && !isPaperparsing) historyPrice.put(date, Double.parseDouble(res[1])); } } catch (Exception e) { // do nothing } } if (visitedNode.toSource().startsWith("g =")) { stop = true; } return true; }); }
Example #16
Source File: MTGoldFishDashBoard.java From MtgDesktopCompanion with GNU General Public License v3.0 | 4 votes |
public HistoryPrice<MagicCard> getOnlinePricesVariation(MagicCard mc, MagicEdition me) throws IOException { String url = ""; HistoryPrice<MagicCard> historyPrice = new HistoryPrice<>(mc); historyPrice.setCurrency(getCurrency()); if(mc==null && me==null) return historyPrice; if (mc == null) { url = getString(URL_EDITIONS) + replace(me.getId(), false) + "#" + getString(FORMAT); } else { if (me == null) me = mc.getCurrentSet(); String cardName = RegExUtils.replaceAll(mc.getName(), " ", "+"); cardName = RegExUtils.replaceAll(cardName, "'", ""); cardName = RegExUtils.replaceAll(cardName, ",", ""); cardName = RegExUtils.replaceAll(cardName, "-", "+"); if (cardName.indexOf('/') > -1) cardName = cardName.substring(0, cardName.indexOf('/')).trim(); String editionName = RegExUtils.replaceAll(me.toString(), " ", "+"); editionName = RegExUtils.replaceAll(editionName, "'", ""); editionName = RegExUtils.replaceAll(editionName, ",", ""); editionName = RegExUtils.replaceAll(editionName, ":", ""); String foil=""; if(me.isFoilOnly()) foil=":Foil"; url = getString(WEBSITE) + "/price/" + convert(editionName) + foil+"/" + cardName + "#" + getString(FORMAT); } try { Document d = URLTools.extractHtml(url); parsing(d,historyPrice); return historyPrice; } catch (Exception e) { logger.error(e); return historyPrice; } }
Example #17
Source File: MTGADecksSniffer.java From MtgDesktopCompanion with GNU General Public License v3.0 | 4 votes |
@Override public List<RetrievableDeck> getDeckList() throws IOException { List<RetrievableDeck> ret = new ArrayList<>(); RequestBuilder e = RequestBuilder.build() .setClient(URLTools.newClient()) .method(METHOD.GET) .url(URL+"/serverSide") .addHeader("x-requested-with", "XMLHttpRequest") .addContent("draw", "2") .addContent("start", "0") .addContent("length", "100") .addContent("search[value]", "") .addContent("search[regex]", FALSE) .addContent("draw", "2") .addContent("columns[0][data]","0") .addContent("columns[0][name]","deckname") .addContent("columns[0][searchable]",FALSE) .addContent("columns[0][orderable]",TRUE) .addContent("columns[0][orderable]","") .addContent("columns[0][search][regex]",FALSE) .addContent("columns[1][data]","1") .addContent("columns[1][name]","colors") .addContent("columns[1][searchable]",FALSE) .addContent("columns[1][orderable]",FALSE) .addContent("columns[1][search][value]","") .addContent("columns[1][search][regex]",FALSE) .addContent("columns[2][data]","2") .addContent("columns[2][name]","archetype") .addContent("columns[2][searchable]",FALSE) .addContent("columns[2][orderable]",FALSE) .addContent("columns[2][search][value]","") .addContent("columns[2][search][regex]",FALSE) .addContent("columns[3][name]","real_update") .addContent("columns[3][searchable]",FALSE) .addContent("columns[3][orderable]",TRUE) .addContent("columns[3][search][value]","") .addContent("columns[3][search][regex]",FALSE) .addContent("&order[0][column]","3") .addContent("&order[0][dir]","desc"); if(!getString(FORMAT).isEmpty()) e.addContent("data", "archetype="+ArrayUtils.indexOf(listFilter(), getString(FORMAT))); JsonArray arr = e.toJson().getAsJsonObject().get("data").getAsJsonArray(); arr.forEach(a->{ RetrievableDeck deck = new RetrievableDeck(); String name = URLTools.toHtml(a.getAsJsonArray().get(0).getAsString()).select("a").text(); name = name.substring(0,name.indexOf(" by ")); name = RegExUtils.replaceAll(name, "BO1","").trim(); deck.setName(name); try { deck.setUrl(new URI(URL+URLTools.toHtml(a.getAsJsonArray().get(0).getAsString()).select("a").attr("href"))); } catch (URISyntaxException e1) { logger.error(e1); } deck.setAuthor(URLTools.toHtml(a.getAsJsonArray().get(0).getAsString()).select("p").text()); String colors = URLTools.toHtml(a.getAsJsonArray().get(1).getAsString()).select("img").attr("alt"); StringBuilder deckColor = new StringBuilder(); for(int i=0;i<colors.length();i++) deckColor.append("{").append(String.valueOf(colors.charAt(i)).toUpperCase()).append("}"); deck.setColor(deckColor.toString()); deck.setDescription(URLTools.toHtml(a.getAsJsonArray().get(2).getAsString()).text()); ret.add(deck); }); return ret; }
Example #18
Source File: Crypto.java From mangooio with Apache License 2.0 | 4 votes |
public String getSizedSecret(String secret) { Objects.requireNonNull(secret, Required.SECRET.toString()); String key = RegExUtils.replaceAll(secret, "[^\\x00-\\x7F]", ""); return key.length() < MAX_KEY_LENGTH ? key : key.substring(KEYINDEX_START, MAX_KEY_LENGTH); }
Example #19
Source File: Application.java From mangooio with Apache License 2.0 | 4 votes |
private static int getBitLength(String secret) { Objects.requireNonNull(secret, Required.SECRET.toString()); return ByteUtils.bitLength(RegExUtils.replaceAll(secret, "[^\\x00-\\x7F]", "")); }
Example #20
Source File: AetherhubDeckSniffer.java From MtgDesktopCompanion with GNU General Public License v3.0 | 4 votes |
@Override public MagicDeck getDeck(RetrievableDeck info) throws IOException { String uri="https://aetherhub.com/Deck/FetchDeckExport?deckId="+info.getUrl().getQuery().replace("id=",""); Document d =URLTools.extractHtml(info.getUrl().toURL()); String data = URLTools.extractAsString(uri); MagicDeck deck = new MagicDeck(); deck.setName(info.getName()); deck.setDescription(d.select("div.decknotes").text()); boolean sideboard=false; data = RegExUtils.replaceAll(data,"\\\\r\\\\n","\n"); data = RegExUtils.replaceAll(data,"\"",""); System.out.println(data); String[] lines = data.split("\n"); for(int i=0;i<lines.length;i++) { String line=lines[i].trim(); if(line.startsWith("Sideboard") || line.startsWith("Maybeboard")) { sideboard=true; } else if(!StringUtils.isBlank(line) && !line.equals("Deck")) { SimpleEntry<String, Integer> entry = parseString(line); try { MagicCard mc = MTGControler.getInstance().getEnabled(MTGCardsProvider.class).searchCardByName(entry.getKey(), null, true).get(0); notify(mc); if(sideboard) deck.getSideBoard().put(mc, entry.getValue()); else deck.getMain().put(mc, entry.getValue()); } catch(Exception e) { logger.error("couldn't not find " + entry.getKey()); } } } return deck; }
Example #21
Source File: Slugger.java From cerberus with Apache License 2.0 | 4 votes |
public String slugifyKmsAliases(String input) { return RegExUtils.replacePattern(input, "[^a-zA-Z0-9:/_-]+", "-"); }
Example #22
Source File: GitHubPushPayload.java From gocd with Apache License 2.0 | 4 votes |
@Override public String getBranch() { return RegExUtils.replaceAll(ref, "refs/heads/", ""); }
Example #23
Source File: GitLabPushPayload.java From gocd with Apache License 2.0 | 4 votes |
@Override public String getBranch() { return RegExUtils.replaceAll(ref, "refs/heads/", ""); }
Example #24
Source File: ScooldUtils.java From scoold with Apache License 2.0 | 4 votes |
public String getSpaceName(String space) { if (DEFAULT_SPACE.equalsIgnoreCase(space)) { return ""; } return RegExUtils.replaceAll(space, "^scooldspace:[^:]+:", ""); }
Example #25
Source File: MTGStockDashBoard.java From MtgDesktopCompanion with GNU General Public License v3.0 | 3 votes |
@Override public HistoryPrice<MagicCard> getOnlinePricesVariation(MagicCard mc, MagicEdition me) throws IOException { if(mc==null) { logger.error("couldn't calculate edition only"); return new HistoryPrice<>(mc); } connect(); Integer id = mc.getMtgstocksId(); if(id==null) { int setId = -1; if (me != null) setId = correspondance.get(me.getId()); else setId = correspondance.get(mc.getCurrentSet().getId()); String url = MTGSTOCK_API_URI + "/search/autocomplete/" + RegExUtils.replaceAll(mc.getName(), " ", "%20"); logger.debug("get prices to " + url); JsonArray arr = URLTools.extractJson(url).getAsJsonArray(); id = arr.get(0).getAsJsonObject().get("id").getAsInt(); logger.trace("found " + id + " for " + mc.getName()); id = searchId(id, setId,URLTools.extractJson(MTGSTOCK_API_URI + "/prints/" + id).getAsJsonObject()); } return extractPrice(URLTools.extractJson(MTGSTOCK_API_URI + "/prints/" + id + "/prices").getAsJsonObject(), mc); }
Example #26
Source File: GenUtils.java From RuoYi-Vue with MIT License | 2 votes |
/** * 关键字替换 * * @param name 需要被替换的名字 * @return 替换后的名字 */ public static String replaceText(String text) { return RegExUtils.replaceAll(text, "(?:表|若依)", ""); }