English 中文(简体)
RegEx: 如何匹配 1 中的“ 任何东西但” 值
原标题:RegEx: How to match "anything but" the value in 1
  • 时间:2012-05-24 04:42:10
  •  标签:
  • regex

I m looking for extra names in a list of name-value pairs. Only the names "ACTIVITY_nnnnn" are of interest. Each name suffix "_nnnnn" should be the same, and if it s not, this is an error condition that should be detected.

Given:

OneTwo=ThreeFour
ACTIVITY_11111=56676566
ACTIVITY_11111=ASDFASDF
ACTIVITY_22222=ASDFwSDF
ABC-123=1121
ACTIVITY_33333=ASDFASsF
ACTIVITY_11111=ASFAFA
DEF-XXY=22222

在此情况下,第一个错配出现在 ACTIVITY_11111 vs. ACTIVITY_22222 中。

当找到另一个匹配条目时, 此表达式会找到匹配项 :

ACTIVITY_(d*=)(.|
|
)*ACTIVITY_1

This is exactly the opposite of what I need...if "Not 1" was possible, then the expression would match if another entry had a different suffix.

Is there a way to specify something like ^1 or [^1]? The word at 1 can be anything but the value in the capture group.

最佳回答

我认为你要求的是:

ACTIVITY_(d*=)(.|
|
)*ACTIVITY_(?!1)

但(1) 我不清楚是否允许团体在外观上出现, (2) 它并不完全按照您的意愿行事 - 它会匹配“ each Actionivity_11111 ” 和“ activitity_ 22222 (这样您就可以得到多个匹配, 或者只得到一个匹配, 或者从头111111而不是最后的匹配 ) 。

我认为你需要的是:

ACTIVITY_(d*=).*[
]((?!ACTIVITY).*[
])*ACTIVITY_(?!1)

中间区中跳过不匹配的活动的附加材料(当然,如果上面(1) 是一个问题, 可能取决于您的正则表达式库, 则不会奏效) 。

问题回答

暂无回答




相关问题
Uncommon regular expressions [closed]

Recently I discovered two amazing regular expression features: ?: and ?!. I was curious of other neat regex features. So maybe you would like to share some tricky regular expressions.

regex to trap img tag, both versions

I need to remove image tags from text, so both versions of the tag: <img src="" ... ></img> <img src="" ... />

C++, Boost regex, replace value function of matched value?

Specifically, I have an array of strings called val, and want to replace all instances of "%{n}%" in the input with val[n]. More generally, I want the replace value to be a function of the match ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

Is it possible to negate a regular expression search?

I m building a lexical analysis engine in c#. For the most part it is done and works quite well. One of the features of my lexer is that it allows any user to input their own regular expressions. This ...

regex for four-digit numbers (or "default")

I need a regex for four-digit numbers separated by comma ("default" can also be a value). Examples: 6755 3452,8767,9865,8766,3454 7678,9876 1234,9867,6876,9865 default Note: "default" ...

热门标签