开发者

javascript: a regular expression for "somestring A.B.C(anything can be here)"

Given a string like, "xyz A.B.C.(anything)" (开发者_StackOverflow社区there's at least one space/tab/newline between z and A.)

I'd like to find "A.B.C".


Something like this:

^\w+\s+((?:[A-Z]\.)+).*$

Gives the following matches (as seen on rubular.com):

matched input        -> group 1 capture
---------------------------------------
xyz A.B.C.whatever   -> A.B.C.
blahblah X.Y.bloop   -> X.Y.

If this is not what you want, then go back and forth with me on rubular and we'll develop the pattern together.


You probably need to be more specific about what it is you are trying to match exactly.

If it's just letters with a dot followed by them (no whitespace between them), then this will work:

/xyz\s+((?:[A-Z]\.)+)/

(It will put them in the first back reference (i.e. $1).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜