开发者

Regexp of number and of any length

I know exact prefix of the String.

E.g. it is 'XXX000'

After the prefix, digits and chars in quantity of 60 go.

How to construct regexp this case?

In my in开发者_如何学Citial understanding it should looks like:

(XXX000)(\w{*})

like: prefix(some digits or some chars)


Use this /XXX000(\w{0,60})/

/    <- Start of the regex
    XXX000    <- Your constant prefix (don't really need to capture it then)
    (         <- Capture the following matching elements
        \w        <- Every characters in [a-zA-Z0-9_]
        {0,60}    <- Between 0 and 60 repetitions of the last element

    )         <- End of the group
/    <- End of the regex

If you don't want the [a-zA-Z0-9_] chars, replace by your own character class.

Note : You may not need delimiters, remember to remove them if it's the case.


Resources :

  • regular-expressions.info - Repetition


If you need to match exactly 60 chars, it's

XXX000\w{60}

It's unnecessary to group with the parens unless you need to capture the part of the match. http://download.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜