正则表达式在java中失败

时间:2017-01-04 02:59:00

标签: java regex regex-lookarounds

我的文件名以%payslip%.xml.gpg开头。

以下是可能的文件名示例:

Taswkly_payslips_Pay27.xml.gpg
exec_payslip.xml.gpg
Cairns_payslips_adv_P27.xml.gpg

请你帮我建一下上面模式名称的正则表达式。

在上面的模式中,事情是固定的,即

*payslip*.xml.gpg.

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:2)

您可以使用此正则表达式:

^.*payslip.*\.xml\.gpg$

^            start of the line
.*           any character multiple times
payslip      the string "payslip"
.*           any character multiple times
\.           the "." character
xml          the string "xml"
\.           the "." character
gpg          the string "gpg"
$            end of the line

另外不要忘记在java中逃避它

^.*payslip.*\\.xml\\.gpg$

Working example

相关问题