cn.hutool.core.util.ReUtil Java Examples

The following examples show how to use cn.hutool.core.util.ReUtil. 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: JsonBeautyListener.java    From MooTool with MIT License 5 votes vote down vote up
private static void find() {
    JsonBeautyForm jsonBeautyForm = JsonBeautyForm.getInstance();

    String content = jsonBeautyForm.getTextArea().getText();
    String findKeyWord = jsonBeautyForm.getFindTextField().getText();
    boolean isMatchCase = jsonBeautyForm.getFindMatchCaseCheckBox().isSelected();
    boolean isWords = jsonBeautyForm.getFindWordsCheckBox().isSelected();
    boolean useRegex = jsonBeautyForm.getFindUseRegexCheckBox().isSelected();

    int count;
    String regex = findKeyWord;

    if (!useRegex) {
        regex = ReUtil.escape(regex);
    }
    if (isWords) {
        regex = "\\b" + regex + "\\b";
    }
    if (!isMatchCase) {
        regex = "(?i)" + regex;
    }

    count = ReUtil.findAll(regex, content, 0).size();
    content = ReUtil.replaceAll(content, regex, "<span>$0</span>");

    FindResultForm.getInstance().getFindResultCount().setText(String.valueOf(count));
    FindResultForm.getInstance().setHtmlText(content);
    FindResultFrame.showResultWindow();
}
 
Example #2
Source File: JsonBeautyListener.java    From MooTool with MIT License 5 votes vote down vote up
private static void replace() {
    JsonBeautyForm jsonBeautyForm = JsonBeautyForm.getInstance();
    String target = jsonBeautyForm.getFindTextField().getText();
    String replacement = jsonBeautyForm.getReplaceTextField().getText();
    String content = jsonBeautyForm.getTextArea().getText();
    boolean isMatchCase = jsonBeautyForm.getFindMatchCaseCheckBox().isSelected();
    boolean isWords = jsonBeautyForm.getFindWordsCheckBox().isSelected();
    boolean useRegex = jsonBeautyForm.getFindUseRegexCheckBox().isSelected();

    String regex = target;

    if (!useRegex) {
        regex = ReUtil.escape(regex);
    }
    if (isWords) {
        regex = "\\b" + regex + "\\b";
    }
    if (!isMatchCase) {
        regex = "(?i)" + regex;
    }

    content = ReUtil.replaceAll(content, regex, replacement);

    jsonBeautyForm.getTextArea().setText(content);
    jsonBeautyForm.getTextArea().setCaretPosition(0);
    jsonBeautyForm.getScrollPane().getVerticalScrollBar().setValue(0);
    jsonBeautyForm.getScrollPane().getHorizontalScrollBar().setValue(0);
}
 
Example #3
Source File: QuickNoteListener.java    From MooTool with MIT License 5 votes vote down vote up
private static void find() {
    QuickNoteForm quickNoteForm = QuickNoteForm.getInstance();

    String content = quickNoteForm.getTextArea().getText();
    String findKeyWord = quickNoteForm.getFindTextField().getText();
    boolean isMatchCase = quickNoteForm.getFindMatchCaseCheckBox().isSelected();
    boolean isWords = quickNoteForm.getFindWordsCheckBox().isSelected();
    boolean useRegex = quickNoteForm.getFindUseRegexCheckBox().isSelected();

    int count;
    String regex = findKeyWord;

    if (!useRegex) {
        regex = ReUtil.escape(regex);
    }
    if (isWords) {
        regex = "\\b" + regex + "\\b";
    }
    if (!isMatchCase) {
        regex = "(?i)" + regex;
    }

    count = ReUtil.findAll(regex, content, 0).size();
    content = ReUtil.replaceAll(content, regex, "<span>$0</span>");

    FindResultForm.getInstance().getFindResultCount().setText(String.valueOf(count));
    FindResultForm.getInstance().setHtmlText(content);
    FindResultFrame.showResultWindow();
}
 
Example #4
Source File: QuickNoteListener.java    From MooTool with MIT License 5 votes vote down vote up
private static void replace() {
    QuickNoteForm quickNoteForm = QuickNoteForm.getInstance();
    String target = quickNoteForm.getFindTextField().getText();
    String replacement = quickNoteForm.getReplaceTextField().getText();
    String content = quickNoteForm.getTextArea().getText();
    boolean isMatchCase = quickNoteForm.getFindMatchCaseCheckBox().isSelected();
    boolean isWords = quickNoteForm.getFindWordsCheckBox().isSelected();
    boolean useRegex = quickNoteForm.getFindUseRegexCheckBox().isSelected();

    String regex = target;

    if (!useRegex) {
        regex = ReUtil.escape(regex);
    }
    if (isWords) {
        regex = "\\b" + regex + "\\b";
    }
    if (!isMatchCase) {
        regex = "(?i)" + regex;
    }

    content = ReUtil.replaceAll(content, regex, replacement);

    quickNoteForm.getTextArea().setText(content);
    quickNoteForm.getTextArea().setCaretPosition(0);
    quickNoteForm.getScrollPane().getVerticalScrollBar().setValue(0);
    quickNoteForm.getScrollPane().getHorizontalScrollBar().setValue(0);
}
 
Example #5
Source File: FqWebsiteDirController.java    From feiqu-opensource with Apache License 2.0 5 votes vote down vote up
/**
 * ajax添加FqWebsiteDir
 */
@ResponseBody
@PostMapping("/add")
public Object add(FqWebsiteDir fqWebsiteDir, HttpServletRequest request, HttpServletResponse response) {
    BaseResult result = new BaseResult();
    if(StringUtils.isBlank(fqWebsiteDir.getName()) || StringUtils.isBlank(fqWebsiteDir.getType())){
        result.setResult(ResultEnum.PARAM_NULL);
        return result;
    }

    if(!ReUtil.isMatch(PatternPool.URL,fqWebsiteDir.getUrl())){
        result.setResult(ResultEnum.WEBSITE_URL_ERROR);
        return result;
    }
    FqUserCache fqUserCache = getCurrentUser();
    try {
        FqWebsiteDirExample example = new FqWebsiteDirExample();
        example.createCriteria().andUrlEqualTo(fqWebsiteDir.getUrl()).andDelFlagEqualTo(YesNoEnum.NO.getValue());
        FqWebsiteDir fqWebsiteDirDB = fqWebsiteDirService.selectFirstByExample(example);
        if(fqWebsiteDirDB != null){
            result.setResult(ResultEnum.WEBSITE_URL_EXISTS);
            return result;
        }

        fqWebsiteDir.setDelFlag(YesNoEnum.NO.getValue());
        fqWebsiteDir.setUserId(fqUserCache == null?0:fqUserCache.getId());
        fqWebsiteDir.setCreateTime(new Date());
        fqWebsiteDir.setClickCount(0);
        fqWebsiteDirService.insert(fqWebsiteDir);
        CacheManager.refreshWebsiteCache();
    } catch (Exception e) {
        logger.error("发生系统错误",e);
        result.setResult(ResultEnum.SYSTEM_ERROR);
        return result;
    }
    return result;
}
 
Example #6
Source File: JobController.java    From feiqu-opensource with Apache License 2.0 5 votes vote down vote up
@RequestMapping("")
    public String index(HttpServletRequest request, HttpServletResponse response, @RequestParam(defaultValue = "1") Integer pageIndex,
                        @RequestParam(defaultValue = "20") Integer pageSize){
        JobTalkExample example = new JobTalkExample();
        example.setOrderByClause("create_time desc");
        PageHelper.startPage(pageIndex,pageSize);
        List<JobTalkUserDetail> jobTalkList = jobTalkService.selectWithUserByExample(example);
        PageInfo page = new PageInfo(jobTalkList);
//        Integer count = jobTalkService.countByExample(example);
        request.setAttribute("count",page.getTotal());
        String content = "";
        Pattern pattern = Pattern.compile("<img.*src=(.*?)[^>]*?>");
        List<String> imgUrlList = null;
        for(JobTalkUserDetail jobTalkUserDetail : jobTalkList){
            content = jobTalkUserDetail.getContent();
            int imgIndex = content.indexOf("<img");
            if(imgIndex >= 0){
                imgUrlList = ReUtil.getAllGroups(pattern,content);
                content = ReUtil.delAll(pattern,content);
                if(content.length() > 50){
                    content = StringUtils.substring(content,0,50) +"...<br>"+ StringUtils.join(imgUrlList.toArray());;
                }else {
                    content+= StringUtils.join(imgUrlList.toArray());
                }
            }else {
                if(content.length() > 50){
                    content = StringUtils.substring(content,0,50) +"...";
                }
            }
            jobTalkUserDetail.setContent(content);
        }
        request.setAttribute("jobTalkList",jobTalkList);
        request.setAttribute("pageIndex",pageIndex);
        return "/job/index.html";
    }
 
Example #7
Source File: TestString.java    From Jpom with MIT License 5 votes vote down vote up
public static void main(String[] args) {
//        System.out.println(CheckPassword.checkPassword("123aA!"));
//        DateTime dateTime = DateUtil.parseUTC("2019-04-04T10:11:21Z");
//        System.out.println(dateTime);
//        dateTime.setTimeZone(TimeZone.getDefault());
//        System.out.println(dateTime);
        Pattern pattern = Pattern.compile("(https://|http://)?([\\w-]+\\.)+[\\w-]+(:\\d+|/)+([\\w- ./?%&=]*)?");
        String url = "http://192.168.1.111:2122/node/index.html?nodeId=dyc";
        System.out.println(ReUtil.isMatch(pattern, url));
        System.out.println(ReUtil.isMatch(PatternPool.URL_HTTP, url));


//        System.out.println(FileUtil.file("/a", null, "", "ss"));

        System.out.println(Math.pow(1024, 2));

        System.out.println(Integer.MAX_VALUE);

        while (true) {
            SortedMap<String, Charset> x = Charset.availableCharsets();
            Collection<Charset> values = x.values();
            boolean find = false;
            for (Charset charset : values) {
                String name = charset.name();
                if ("utf-8".equalsIgnoreCase(name)) {
                    find = true;
                    break;
                }
            }
            if (!find) {
                System.out.println("没有找utf-8");
            }
        }
//        System.out.println(x);
    }
 
Example #8
Source File: WxArticleTemplateServiceImpl.java    From cms with Apache License 2.0 5 votes vote down vote up
private String processContent(String content) {
    if (StringUtils.isBlank(content)) {
        return content;
    }
    String imgReg = "<img[^>]+src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>";
    List<String> imgList = ReUtil.findAllGroup1(imgReg, content);
    for (int j = 0; j < imgList.size(); j++) {
        String image = imgList.get(j);
        WxMediaUploadResult mediaUploadResult = wechatService.addMedia(image);
        content = StringUtils.replace(content, imgList.get(j), mediaUploadResult.getUrl());
    }
    return content;
}
 
Example #9
Source File: CommonUtils.java    From feiqu-opensource with Apache License 2.0 4 votes vote down vote up
public static List<String> findAiteNicknames(String content){
    return ReUtil.findAll(aitePattern,content,1);
}
 
Example #10
Source File: DocumentBrowser.java    From book118-downloader with MIT License 4 votes vote down vote up
/**
 * 获取文档的预览地址
 *
 * @param documentId 文档的编号
 * @return 预览地址
 */
private PdfInfo getPdfInfo(String documentId) {
    String url = Constants.OPEN_FULL_URL + documentId;
    String pdfPageUrlStr = HttpUtil.get(url);

    if (StrUtil.isNotBlank(pdfPageUrlStr)) {
        pdfPageUrlStr = "https:" + pdfPageUrlStr;
    } else {
        StaticLog.error("获取失败!");
        return null;
    }

    int endOfHost = pdfPageUrlStr.indexOf("?");
    String viewHost = pdfPageUrlStr.substring(0, endOfHost);
    String redirectPage = HttpUtil.get(pdfPageUrlStr);
    String href = ReUtil.get(Constants.HREF_PATTERN, redirectPage, 1);
    String fullUrl;
    if(href != null){
        fullUrl = viewHost.substring(0, viewHost.length()-1) + HtmlUtil.unescape(href);
    }else {
        fullUrl = pdfPageUrlStr;
    }


    String pdfPageHtml = HttpUtil.get(fullUrl);
    if (pdfPageHtml.contains(Constants.FILE_NOT_EXIST)) {
        StaticLog.error("获取预览地址失败,请稍后再试!");
        return null;
    }

    List<String> result = ReUtil.findAllGroup0(Constants.INPUT_PATTERN, pdfPageHtml);
    Map<String, String> pdfInfoMap = new HashMap<>(6);
    pdfInfoMap.put("host", viewHost);
    for (String inputStr : result) {
        String id = ReUtil.get(Constants.ID_PATTERN, inputStr, 1);
        String value = ReUtil.get(Constants.VALUE_PATTERN, inputStr, 1);
        if (StrUtil.isNotBlank(id) && StrUtil.isNotBlank(value)) {
            id = id.toLowerCase();
            try {
                value = URLEncoder.encode(value, "utf8");
            } catch (Exception e) {
                StaticLog.error("URLEncoder Error", e);
            }
            pdfInfoMap.put(id, value);
        }
    }
    return BeanUtil.mapToBean(pdfInfoMap, PdfInfo.class, true);
}
 
Example #11
Source File: Dc3Util.java    From iot-dc3 with Apache License 2.0 2 votes vote down vote up
/**
 * 判断字符串是否为 用户名格式(2-32)
 *
 * @param name String
 * @return boolean
 */
public static boolean isName(String name) {
    String regex = "^[A-Za-z0-9\\u4e00-\\u9fa5][A-Za-z0-9\\u4e00-\\u9fa5-_]{1,31}$";
    return ReUtil.isMatch(regex, name);
}
 
Example #12
Source File: Dc3Util.java    From iot-dc3 with Apache License 2.0 2 votes vote down vote up
/**
 * 判断字符串是否为 手机号码格式
 *
 * @param phone String
 * @return boolean
 */
public static boolean isPhone(String phone) {
    String regex = "^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\\d{8}$";
    return ReUtil.isMatch(regex, phone);
}
 
Example #13
Source File: Dc3Util.java    From iot-dc3 with Apache License 2.0 2 votes vote down vote up
/**
 * 判断字符串是否为 邮箱地址格式
 *
 * @param mail String
 * @return boolean
 */
public static boolean isMail(String mail) {
    String regex = "^([a-zA-Z0-9_\\.\\-])+\\@(([a-zA-Z0-9\\-])+\\.)+([a-zA-Z0-9]{2,4})+$";
    return ReUtil.isMatch(regex, mail);
}
 
Example #14
Source File: Dc3Util.java    From iot-dc3 with Apache License 2.0 2 votes vote down vote up
/**
 * 判断字符串是否为 密码格式(8-16)
 *
 * @param password String
 * @return boolean
 */
public static boolean isPassword(String password) {
    String regex = "^[a-zA-Z]\\w{7,15}$";
    return ReUtil.isMatch(regex, password);
}
 
Example #15
Source File: Dc3Util.java    From iot-dc3 with Apache License 2.0 2 votes vote down vote up
/**
 * 判断字符串是否为 Host格式
 *
 * @param host String
 * @return boolean
 */
public static boolean isHost(String host) {
    String regex = "^((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})(\\.((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})){3}$";
    return ReUtil.isMatch(regex, host);
}
 
Example #16
Source File: Dc3Util.java    From iot-dc3 with Apache License 2.0 2 votes vote down vote up
/**
 * 判断字符串是否为 驱动端口格式
 *
 * @param port Integer
 * @return boolean
 */
public static boolean isDriverPort(int port) {
    String regex = "^8[6-7][0-9]{2}$";
    return ReUtil.isMatch(regex, String.valueOf(port));
}