这个正则表达式意味着什么[A-Z0-9 ._%+ - ] ..你能否回答这个问题

时间:2016-05-13 07:05:37

标签: java regex

Pattern.compile( “[A-Z0-9 ._%+ - ]”) 什么编译???

2 个答案:

答案 0 :(得分:4)

[A-Z0-9._%+-] match a single character present in the list below
A-Z a single character in the range between A and Z (case sensitive)
0-9 a single character in the range between 0 and 9
._%+- a single character in the list ._%+- literally

您可以使用以下网站来了解和测试正则表达式: https://regex101.com/

答案 1 :(得分:0)

正则表达式被称为“已编译”,这意味着字符串将转换为比较对象树。稍后将使用比较对象树与一些字符串(或字符串)进行比较,以查看它是否匹配。

对于你的问题中的正则表达式,它可以被解释为匹配任何单个字符:

  • 介于A和Z之间,或
  • 介于0和9之间,或
  • '。','_','%','+'或' - '
  • 中的任何一个

这个正则表达式可能用于匹配url参数,编程语言中的变量名或类似的东西。