Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个允许采用多种格式的日期:
24-01-12 january 24 2013 etc
有没有办法使用管道或其他方法将 2 个或多个不同的正则表达式组合成一个?我试过嵌套括号,但这当然不起作用:
[regex | regex]
是的,试试这个:
(\d\d-\d\d-\d\d)|([a-z]*) // So basically: (regex)|(regex)
这匹配所有单词,以及第一行中的日期。 ((?:regex)如果您想要非捕获组,而不是捕获组,请使用。)
(?:regex)
如果您确实将您的正则表达式放在 中[],那么这就是问题所在。
[]