负向前瞻/后视 [英] Negative lookahead/lookbehind

查看:92
本文介绍了负向前瞻/后视的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个声明,让我识别我的客户输入的格式错误的文本。格式良好的语句如下所示:

I am trying to craft a statement that will let me identity malformed text entered by my clients.  A well-formed statement will look like the following:

##< 1到50个字母字符和0到5个数字> ##

##<1 to 50 alpha characters and 0 to 5 numbers>##

我提出的陈述如下,但似乎不起作用。任何帮助将不胜感激。

The statement I've come up with is the following, but it doesn't appear to work.  Any help would be appreciated.

\#\#(?![a-zA-Z] {1,50}( ?:: [\d] {0,5})\#\#)|(小于?!\?#\#[A-ZA-Z] {1,50}(:: [\ d] {0,5})?)\#\#

\#\#(?![a-zA-Z]{1,50}(?::[\d]{0,5})?\#\#)|(?<!\#\#[a-zA-Z]{1,50}(?::[\d]{0,5})?)\#\#

推荐答案

模式的第一部分使用 Match Invalidator ?这意味着如果匹配发生,取消停止任何更多匹配。如果您使用有效格式,则创建一个看起来像这样的模式,并且无法匹配任何其他模式。只用?!当一个人有一个有效的格式,但内部有问题或匹配过程需要停止

使用Match invalidator查看我的博客和SSN示例:正则表达式(正则表达式)匹配.Net中的无效者(?!)。 HTH
The first part of the pattern uses the Match Invalidator ?! which means if the match occurs, cancel stop any more matching. If you have a valid format create a pattern which looks like that and fails to match on anything else. Only use the ?! when one has a valid format but internally something is wrong or the matching process needs to stop .

Check out my blog and a SSN example using the Match invalidator: Regular Expression (Regex) Match Invalidator (?!) in .Net . HTH


这篇关于负向前瞻/后视的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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