类 RegularUtil
java.lang.Object
org.anyline.util.regular.RegularUtil
-
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static String取tags[i-2]与tags[i-1]之间的文本static Stringfetch(String src, String regx, Regular.MATCH_MODE mode) fetch(String src, String regx, Regular.MATCH_MODE mode, int idx) fetchAllTag(String txt, String... tags) 提取单标签+双标签 不区分大小写 0:全文 1:开始标签 2:标签name 3:标签体 (单标签时null) 4:结束标签 (单标签时null)fetchAttribute(String txt, String attribute) 取出属性及属性值 0全文 1:属性name 2:引号('|") 3:属性值 fetchAttributeValues(txt, "id","name");fetchAttributeList(String txt, String attribute) 取出所有属性值 0全文 1:属性name 2:引号('|") 3:属性值 fetchAttributeValues(txt, "id");static StringfetchAttributeValue(String txt, String attribute) 取出的属性值(有多个的取第一个)fetchAttributeValues(String txt, String attribute) 取出所有的属性值static StringfetchNumber(String src) fetchNumbers(String src) fetchPairedTag(String txt, String... tags) 提取双标签<div>content<div> 依次取出p, table, div中的内容 有嵌套时只取外层 只能提取同时有 开始结束标签的内容, 不能提取单标签内容如<img> <br/> 支持不同标签嵌套, 但不支持相同标签嵌套 不区分大小写 0:全文 1:开始标签 2:标签name 3:标签体 4:结束标签fetchs(String src, String regx, Regular.MATCH_MODE mode) 提取子串fetchSingleTag(String txt, String... tags) 提取单标签 如<img> <br/> 如果传入div等带有结束标签的参数 则只取出开始标签 <div> 不区分大小写 0:全文 1::标签namestatic String提取所有a棱中的urlfilter(List<String> src, String regx, Regular.MATCH_MODE mode, Regular.FILTER_TYPE type) getTagWithBodyByAttribute(String src, String attribute) 获取所有 包含attribute属性 的标签与标签体, 不支持相同标签嵌套
[
[整个标签含标签体, 开始标签, 结束标签, 标签体, 标签名称],
[整个标签含标签体, 开始标签, 结束标签, 标签体, 标签名称]
]getTagWithBodyByAttributeValue(String src, String attribute, String value) 获取所有 包含attribute属性并且值=value 的标签与标签体
单标签只匹配有/>结尾的情况, 避免与双标签的开始标签混淆
如class="a" : attribute=class value=a
style="width:100px;" :attribute=style value=width
[
[整个标签含标签体, 开始标签, 结束标签, 标签体, 标签名称],
[整个标签含标签体, 开始标签, 结束标签, 标签体, 标签名称]
]static intstatic int字符串下标 regx在src中首次出现的位置static booleanstatic booleanisDateTime(String str) static booleanstatic booleanstatic booleanmatch(String src, String regx, Regular.MATCH_MODE mode) pick(List<String> src, String regx, Regular.MATCH_MODE mode) 过滤 保留匹配项regexpValue(String src, String regex, Regular.MATCH_MODE mode) 表达式匹配值长度static StringremoveAttribute(String src, String... attributes) 删除所有标签的属性 只删除属性 不删除标签与标签体static StringremoveEmptyTag(String src) 删除所有空标签static StringremoveHtmlEmptyTag(String src) static StringremoveHtmlTag(String src, String... tags) static StringremoveHtmlTagExcept(String src, String... tags) static String删除简单标签外的其他标签static StringremoveHtmlTagWithBody(String src, String... tags) static String清除所有标签(只清除标签, 不清除标签体)static StringremoveTagByAttribute(String src, String attribute) 根据属性名 删除标签(只删除标签, 保留标签体)static StringremoveTagByAttributeValue(String src, String attribute, String value) 根据属性名与属性值 删除标签(只删除标签, 保留标签体)static StringremoveTagExcept(String src, String... tags) 删除 tags之外的标签"<b>"与"</b>"只写一次 "b"
只删除标签不删除标签体static StringremoveTagWithBody(String src, String... tags) 删除标签及标签体static StringremoveTagWithBodyByAttribute(String src, String attribute) 删除所有 包含attribute属性 的标签 连同标签体一起删除
RegularUtil.removeTagWithBodyByAttribute(str, "class")
<input type="text" class="a"/>
<input type="text" class="a"></input>
<input type="text" class = "a"></input>
<input type="text" class></input>
<input type="text" class/>
<input type="text" a="class"></input>(不匹配)static StringremoveTagWithBodyByAttributeValue(String src, String attribute, String value) 删除所有 包含attribute属性=value值 的标签连同标签体一起删除
RegularUtil.removeTagWithBodyByAttributeValue(s, "class","a")
<input type="text" class="a"/>
<input type="text" class="a"/></input/>
<input type="text" class="a b"/></input/>如果需要不匹配可以使用"[^\\s]a[^\\s]"
<input type="text" class="b a"/></input/>
<input type="text" class="ab"/></input/>(不匹配)如果需要匹配可以使用"awipe(List<String> src, String regx, Regular.MATCH_MODE mode) 过滤 删除匹配项
-
字段详细资料
-
构造器详细资料
-
RegularUtil
public RegularUtil()
-
-
方法详细资料
-
match
-
match
-
fetchs
public static List<List<String>> fetchs(String src, String regx, Regular.MATCH_MODE mode) throws Exception 提取子串- 参数:
src- 输入字符串 src 输入字符串regx- 表达式 regx 表达式mode- mode- 返回:
- List
- 抛出:
Exception- 异常 Exception
-
fetchs
- 抛出:
Exception
-
fetch
- 抛出:
Exception
-
fetch
public static List<String> fetch(String src, String regx, Regular.MATCH_MODE mode, int idx) throws Exception - 抛出:
Exception
-
fetch
- 抛出:
Exception
-
filter
public static List<String> filter(List<String> src, String regx, Regular.MATCH_MODE mode, Regular.FILTER_TYPE type) -
pick
过滤 保留匹配项- 参数:
src- srcregx- regxmode- mode- 返回:
- List
-
wipe
过滤 删除匹配项- 参数:
src- srcregx- regxmode- mode- 返回:
- List
-
indexOf
字符串下标 regx在src中首次出现的位置- 参数:
src- srcregx- regxbegin- 有效开始位置- 返回:
- int
-
indexOf
-
regexpValue
表达式匹配值长度- 参数:
src- srcregex- regexmode- mode- 返回:
- List
-
removeTagWithBodyByAttribute
删除所有 包含attribute属性 的标签 连同标签体一起删除
RegularUtil.removeTagWithBodyByAttribute(str, "class")
<input type="text" class="a"/>
<input type="text" class="a"></input>
<input type="text" class = "a"></input>
<input type="text" class></input>
<input type="text" class/>
<input type="text" a="class"></input>(不匹配)- 参数:
src- srcattribute- 属性- 返回:
- String
-
removeTagWithBodyByAttributeValue
删除所有 包含attribute属性=value值 的标签连同标签体一起删除
RegularUtil.removeTagWithBodyByAttributeValue(s, "class","a")
<input type="text" class="a"/>
<input type="text" class="a"/></input/>
<input type="text" class="a b"/></input/>如果需要不匹配可以使用"[^\\s]a[^\\s]"
<input type="text" class="b a"/></input/>
<input type="text" class="ab"/></input/>(不匹配)如果需要匹配可以使用"a.*"- 参数:
src- xml/htmlattribute- 属性value- 值- 返回:
- String
-
removeTagByAttributeValue
public static String removeTagByAttributeValue(String src, String attribute, String value) throws Exception 根据属性名与属性值 删除标签(只删除标签, 保留标签体)- 参数:
src- xml/htmlattribute- 属性名value- 属性值- 返回:
- String
- 抛出:
Exception
-
removeTagByAttribute
根据属性名 删除标签(只删除标签, 保留标签体)- 参数:
src- xml/htmlattribute- 属性名- 返回:
- String
- 抛出:
Exception
-
getTagWithBodyByAttribute
public static List<List<String>> getTagWithBodyByAttribute(String src, String attribute) throws Exception 获取所有 包含attribute属性 的标签与标签体, 不支持相同标签嵌套
[
[整个标签含标签体, 开始标签, 结束标签, 标签体, 标签名称],
[整个标签含标签体, 开始标签, 结束标签, 标签体, 标签名称]
]- 参数:
src- xml/htmlattribute- 属性- 返回:
- List
- 抛出:
Exception- 异常 Exception
-
getTagWithBodyByAttributeValue
public static List<List<String>> getTagWithBodyByAttributeValue(String src, String attribute, String value) throws Exception 获取所有 包含attribute属性并且值=value 的标签与标签体
单标签只匹配有/>结尾的情况, 避免与双标签的开始标签混淆
如class="a" : attribute=class value=a
style="width:100px;" :attribute=style value=width
[
[整个标签含标签体, 开始标签, 结束标签, 标签体, 标签名称],
[整个标签含标签体, 开始标签, 结束标签, 标签体, 标签名称]
]- 参数:
src- xml/htmlattribute- 属性value- 值- 返回:
- List
- 抛出:
Exception- 异常 Exception
-
removeTagExcept
删除 tags之外的标签"<b>"与"</b>"只写一次 "b"
只删除标签不删除标签体- 参数:
src- htmltags- tags- 返回:
- String
-
removeHtmlTagExcept
-
removeTag
清除所有标签(只清除标签, 不清除标签体)- 参数:
src- xml/htmltags- tags- 返回:
- String
-
removeHtmlTag
-
removeTagWithBody
删除标签及标签体- 参数:
src- xml/htmltags- 标签, 如果不提供则删除所有标签- 返回:
- String
-
removeHtmlTagWithBody
-
removeEmptyTag
删除所有空标签- 参数:
src- xml/html- 返回:
- String
-
removeHtmlEmptyTag
-
removeHtmlTagExceptSimple
删除简单标签外的其他标签- 参数:
src- html- 返回:
- String
-
removeAttribute
删除所有标签的属性 只删除属性 不删除标签与标签体- 参数:
src- xml/htmlattributes- 属性 如果不传则删除所有属性- 返回:
- String
-
fetchUrls
提取所有a棱中的url- 参数:
src- xml/html- 返回:
- list
- 抛出:
Exception- 异常
-
fetchUrl
- 抛出:
Exception
-
fetchNumbers
- 抛出:
Exception
-
fetchNumber
- 抛出:
Exception
-
fetchPairedTag
提取双标签<div>content<div> 依次取出p, table, div中的内容 有嵌套时只取外层 只能提取同时有 开始结束标签的内容, 不能提取单标签内容如<img> <br/> 支持不同标签嵌套, 但不支持相同标签嵌套 不区分大小写 0:全文 1:开始标签 2:标签name 3:标签体 4:结束标签- 参数:
txt- texttags- 标签名, 如div, span tags标签名, 如div, span- 返回:
- List
- 抛出:
Exception- 异常 Exception
-
fetchSingleTag
提取单标签 如<img> <br/> 如果传入div等带有结束标签的参数 则只取出开始标签 <div> 不区分大小写 0:全文 1::标签name- 参数:
txt- texttags- 标签名, 如img br- 返回:
- List
- 抛出:
Exception- 异常 Exception
-
fetchAllTag
提取单标签+双标签 不区分大小写 0:全文 1:开始标签 2:标签name 3:标签体 (单标签时null) 4:结束标签 (单标签时null)- 参数:
txt- txttags- 标签名 tags标签名- 返回:
- List
- 抛出:
Exception- 异常 Exception
-
fetchAttributeList
取出所有属性值 0全文 1:属性name 2:引号('|") 3:属性值 fetchAttributeValues(txt, "id");- 参数:
txt- txtattribute- 属性- 返回:
- List
-
fetchAttribute
取出属性及属性值 0全文 1:属性name 2:引号('|") 3:属性值 fetchAttributeValues(txt, "id","name");- 参数:
txt- txtattribute- 属性- 返回:
- List
-
fetchAttributeValues
取出所有的属性值- 参数:
txt- txtattribute- 属性名- 返回:
- List
-
fetchAttributeValue
取出的属性值(有多个的取第一个)- 参数:
txt- txtattribute- 属性名- 返回:
- String
-
cut
-
cut
取tags[i-2]与tags[i-1]之间的文本- 参数:
text- texttags- tagscontains- 是否包含开始结束标签- 返回:
- String
-
cuts
-
cuts
-
isDate
-
isDateTime
-
isUrl
-