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.
我有一个这样的字符串
file-myfle_20130207_094852am.csv
我该如何编写正则表达式以仅提取数字
20130207094852
像这样(这在正则表达式教程中很常见)
\d+
每组将是数字。
有关上下文,请参阅我对问题的评论。
从外壳:
echo file-myfle_20130207_094852am.csv | tr -cd /0-9/ 20130207094852
使用 Perl:
echo file-myfle_20130207_094852am.csv | perl -pe 's/\D//g' 20130207094852