简体   繁体   English

正则表达式适用于非数字,为什么不适用于数字?

[英]Regex works for non digits, why it doesn't for digits?

You can test it here: http://rubular.com/r/8tNjR6dVRu 您可以在这里进行测试: http : //rubular.com/r/8tNjR6dVRu

Test String: 测试字符串:

                                                                                   Folha: 1 /2
                                      História Escola

 Nome:              MARCOS MARCO MARCA                                                     1111111

 Data Nascimento:   7 de agosto de 2000

Result for 的结果

(?<=Nome:)(\D*)

MARCOS MARCO MARCA 马科斯·马可·马卡

( with spaces. Is there a easy way to remove it? ) (带空格。是否有简单的方法将其删除?)

Now, I wanted to get the numbers, I tried the logical 现在,我想获取数字,我尝试了逻辑

(?<=Nome:)(\d*)

But it doesn't work. 但这是行不通的。

Can someone explain me why? 有人可以解释我为什么吗?

Thanks! 谢谢!

You want to MATCH the non-digits, but CAPTURE the digits: 您要匹配非数字,但要捕获数字:

(?<=Nome:)\D*(\d+)

This starts after the Nome: and ignores everything non-digit. 它从Nome:之后开始Nome:并忽略所有非数字内容。 Then it captures the digits. 然后,它捕获数字。

Rubular demo 演示演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM