开发者

Regular expression - match character, digits and special characters

I have the following string:

test123 test ödo 123teö"st 123 m.1212 123t.est

I only want to match strings as a whole that have either characters, digits and special character mixed together. So the regex should match the following string of the example above:

test123 test ödo 123teö"st 123 m.1212 123t.est

Could someone help me out please?

Update Sorry for not giving a clear explanation of what I need.

  1. I am using C#.

  2. I need to find words that contain alphanumeric strings (eg abc123, 123abc, a1b2c3, 1abc23 etc). Also I need to find strings that contain any kind of symbols (symbols = anythings else than word characters and digits) (eg abc"123, "abc, ab?dd, 100mm", 345t{asd]dd开发者_高级运维)

  3. If I find a match, I need to "tokenize" (separate digits, word characters and symbols with whitespace) these strings so abc123 becomes abc 123 or 345t{asd]dd becomes 345 t { asd ] dd etc


Assuming you're using a regex flavor that supports lookaheads and Unicode properties, this should get you started:

(?!(?:\pL+|\pN+|\pP+)(?!\S))\S+

\S+ matches one or more non-whitespace characters, but only after the negative lookahead asserts that those characters are not all letters (\pL), digits (\pN), or punctuation (\pP). The inner negative lookahead--(?!\S)--ensures that the outer one examines all the characters in the word.

Although it might satisfy your requirements, this regex is really just a demonstration of the technique you'll probably want to use. As it is, it can be fooled by "words" with (for example) control characters or dingbats in them.


The answer to the question you’ve actually asked is (?s).+, but perhaps you would care to refine your question.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜