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.
I am using C#.
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开发者_高级运维)
If I find a match, I need to "tokenize" (separate digits, word characters and symbols with whitespace) these strings so
abc123
becomesabc 123
or345t{asd]dd
becomes345 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.
精彩评论