以下输出需要正则表达式模式 [英] Regex pattern needed for the below output

查看:83
本文介绍了以下输出需要正则表达式模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述







我想要抓住正则表达式:

* Page.7545

* .212

* .12

* testDoc.21

* aw.3





但不是:

* 1000.25
* 2.21

* 898





现在我有



\ b [a-zA-Z] + [。] [\\\] [\d] \b





但它没有帮助。请给我一些解决方案

解决方案

试试这个:

 ^ [a-zA-Z] * [。] [\ d] + \ b 


'更好地教一个人鱼而不是给他一些鱼'



关于正则表达式,我的建议是:



- 准确描述你想要的输出;用字描述,而不是用非详尽的例子描述

应用于你的具体例子,这将给出:

在任何我的输入的一部分,找到:

任何长度的任何字母(大写与否)的序列,后跟一个点,后跟任意长度的任何数字序列




- 使用工具将您的描述翻译成有效的正则表达式。我个人使用 Expresso [ ^ ]为此;此工具允许您使用图形用户界面构建正则表达式,当此表达式的复杂性开始增长时,这不是奢侈的。它还允许您针对多个输入测试您的正则表达式,并对其进行验证。



只需2美分;祝这有帮助:)祝你好运。


让我重新说明正则表达式的条件,以确保我理解正确:

开始是否行一个数字后跟一个点后跟一个或多个数字

^ | [^ \d] \.\d +

Hi,


I'd like the regex to catch:
* Page.7545
* .212
* .12
* testDoc.21
* aw.3


But not:
* 1000.25
* 2.21
* 898


Right now I have

\b[a-zA-Z]+[.][\d][\d]\b


but its not helpful.Please provide me some solution

解决方案

Try this:

^[a-zA-Z]*[.][\d]+\b


'Better teach one to fish rather than give him some fish'

Regarding regular expressions, my advise would be:

- describe precisely what you want as output; describe it with words, not by a non-exhaustive example
Applied to your specific example, this would give:
In any part of my input, find:
A sequence of any letter (capital or not) of any length, followed by a dot, followed by a sequence of any digit of any length


- use a tool to translate your description into a valid regular expression. I personnaly use Expresso[^] for that; this tool allows you to construct your regular expression using a graphical user interface, which is not luxury when the complexity of this expression starts growing. It also allows you to test your regular expression against several inputs, and validate it.

Just my 2 cents; hope this helps :) Good luck.


Let me re-phrase the condition for the regex to make sure I understood it correctly:
Begin of line or not a digit followed by a dot followed by one or more digits
^|[^\d]\.\d+


这篇关于以下输出需要正则表达式模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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