English 中文(简体)
记录
原标题:RegEx pattern any two letters followed by six numbers
  • 时间:2012-05-03 21:36:57
  •  标签:
  • regex

请协助适当的Ref对2封信进行匹配,随后将6个整数合并在一起。

These would be valid: 
RJ123456
PY654321
DD321234

These would not
DDD12345
12DDD123
最佳回答

[a-zA-Z]{2}d{6}

[a-zA-Z]{2} means two letters d{6} means 6 digits

If you want only uppercase letters, then:

[A-Z]{2}d{6}

问题回答

你可以尝试这样的事情:

[a-zA-Z]{2}[0-9]{6}

这里的表述是:

[a-zA-Z]    # Match a single character present in the list below
               # A character in the range between “a” and “z”
               # A character in the range between “A” and “Z”
   {2}         # Exactly 2 times
[0-9]       # Match a single character in the range between “0” and “9”
   {6}         # Exactly 6 times

这将在某个主题中与任何地方相匹配。 如果你需要围绕这一主题划定界限,你可以做以下两种工作:

^[a-zA-Z]{2}[0-9]{6}$

以确保整个主题一致。 一、导 言

or

[a-zA-Z]{2}[0-9]{6}

http://www.google.co.uk/url?sa=t&rct=j&q=word%20boundary%20regex&source=web&cd=1&sqi=2&ved=0CCwQFjA&url=http://www. norm-expressions.info/word约束aries.html&ei=Pv2iT5zYmjiQfyq-Wpw&usg=AFQjprelk=

如“Phrogz”所指出的,你可以通过替换<代码>[0-9]<>>>>而使这一表述变得更可怕,如其他一些答复所示。

[a-zA-Z]{2}d{6}

我取决于你使用什么reg语,但非正式的是:

[:alpha:][:alpha:][:digit:][:digit:][:digit:][:digit:][:digit:][:digit:]

where [:alpha:] = [a-zA-Z] and [:digit:] = [0-9]

如果你使用允许明确重复的常规语言,那么,就象:

[:alpha:]{2}[:digit:]{6}

正确的辛迪加取决于你所使用的特定语言,但这是想法。

Everything you need here can be found in this quickstart guide. A straightforward solution would be [A-Za-z][A-Za-z]dddddd or [A-Za-z]{2}d{6}.

如果你只接受英文大写字母,则将<代码>[A-Za-z]改为[A-Z]

根据您的reg夫的支持,我可以使用:

[A-Z]{2}d{6}    # Ensure there are "word boundaries" on either side, or

(?<![A-Z])[A-Z]{2}d{6}(?!d) # Ensure there isn t a uppercase letter before
                              # and that there is not a digit after




相关问题
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" ...

热门标签