正则表达式:如何匹配不仅仅是数字的字符串 [英] Regex: How to match a string that is not only numbers

查看:45
本文介绍了正则表达式:如何匹配不仅仅是数字的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以编写一个正则表达式来匹配所有不包含数字的字符串?如果我们有这些字符串:

Is it possible to write a regular expression that matches all strings that does not only contain numbers? If we have these strings:

  • abc
  • a4c
  • 4bc
  • ab4
  • 123

它应该首先匹配四个,而不是最后一个.我曾尝试在 RegexBuddy 中摆弄前瞻和其他东西,但我似乎无法弄清楚.

It should match the four first, but not the last one. I have tried fiddling around in RegexBuddy with lookaheads and stuff, but I can't seem to figure it out.

推荐答案

(?!^\d+$)^.+$

这表示先行查找不包含所有数字并匹配整行的行.

This says lookahead for lines that do not contain all digits and match the entire line.

这篇关于正则表达式:如何匹配不仅仅是数字的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆