取消
显示结果 
搜索替代 
您的意思是: 

Match Regular Expression does not match what Match Pattern does

已解决!
转到解答

I have read through a lot of posts about how Match Pattern does not match what Match Regular Expression will due to not processing some characters.

 

However, I found a problem with the other way. A simple Reg-Ex that works in Match Pattern but not Match Regular Expression.

 

What I have here is just an example. I want to use Match Regular Expression so I can specify some sub-matches.

 

The reg-ex is for: one or more non-numeric characters, a space, one or more numeric characters. At the start of the string.

 

How can I get this working in Match Regular Expression? I am working in LabVIEW 2010f2 32 bit. Here is the code snippet and the results:

 

RegEx vs Match Pattern.pngMatch Results.PNG

Rob

0 项奖励
1 条消息(共 4 条)
5,642 次查看
解答
已被主题作者 RobCole 接受

One of the subtle differences is the negation operator for character classes.  In Match Pattern it is ~, but for Match RegEx it is ^.

2 条消息(共 4 条)
5,634 次查看

@Darin.K wrote:

One of the subtle differences is the negation operator for character classes.  In Match Pattern it is ~, but for Match RegEx it is ^.


Thank you Darin. I missed that little difference in the documentation. Everything else looks the same.

 

I think I prefer the ~ for negation since ^ is also used for beginning of the string. But we work with what we have.

 

Rob

0 项奖励
3 条消息(共 4 条)
5,630 次查看

@Robert Cole wrote:

 

I think I prefer the ~ for negation since ^ is also used for beginning of the string. But we work with what we have.

 


Let me offer you a tip and perhaps defend the honor of the regex a little bit.  One of my favorite features of regexes is the ability to specify character classes (and their negation).  One of the reasons I have to think about the ~ versus ^ is that I rarely use ^ in a regex alternative. 

 

Some examples:

[0-9] = \d (digit)

[^0-9] = \D (not a digit)

 

The equivalent regex for your case is: \D+ \d+

 

0 项奖励
4 条消息(共 4 条)
5,611 次查看