Skip to content

Instantly share code, notes, and snippets.

@rj-hwang
rj-hwang / gist:64ec67c3720915bffb2ffde72b6048d9
Created January 16, 2017 02:04
js 正则获取 innerText
var src = 'AAA <a href="https://baidu.com">abc<b>中国</b>123</a>'
var text = src.replace(/<.*?>/ig, '')
// or
var text = src.replace(/(<([^>]+)>)/ig, '')
// result:text="AAA abc中国123"
@rj-hwang
rj-hwang / gist:7338a0a8473572de2645
Created July 22, 2015 07:18
删除 json 字符串中的注释信息
/**
* 删除 json 字符串中的注释信息
* <p>标准的 json 是不允许带注释的,大部分 json 框架都不支持带注释 json 字符串的解析</p>
* @param source 原始 json 字符串
* @return 无注释信息的 json 字符串
*/
public String stripComment(String source) {
return source == null ? null : source.replaceAll("\\s*//.*|(?s)\\s*/\\*(.*?)\\*/[ \\t]*", "");
}
@rj-hwang
rj-hwang / gist:66fa895024c957409e0c
Created July 20, 2015 07:06
ResultSet to Object[]
public Object[] mapRow(ResultSet rs, int rowNum) throws SQLException {
Object[] r = new Object[rs.getMetaData().getColumnCount()];
for (int i = 0; i < r.length; i++) {
r[i] = rs.getObject(i + 1);
}
return r;
}