下面列出了org.apache.commons.lang3.RegExUtils#replaceAll ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
@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));
}
/**
* 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, "'", "\\'"), "\"", "\\\"");
}
/**
* 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, "\'", "\\\'"), "\"", "\\\"");
}
public String getSpaceName(String space) {
if (DEFAULT_SPACE.equalsIgnoreCase(space)) {
return "";
}
return RegExUtils.replaceAll(space, "^scooldspace:[^:]+:", "");
}
@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;
}
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;
}
}
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);
}
@Override
public String getBranch() {
return RegExUtils.replaceAll(ref, "refs/heads/", "");
}
@Override
public String getBranch() {
return RegExUtils.replaceAll(ref, "refs/heads/", "");
}
@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);
}
/**
* 关键字替换
*
* @param name 需要被替换的名字
* @return 替换后的名字
*/
public static String replaceText(String text)
{
return RegExUtils.replaceAll(text, "(?:表|若依)", "");
}