I need to write regex which I will use for asp.net routing constraint which should match any word. The problem is that words could be written in any language, for example
- test
- some-other-test
- one-more-трудно-получить-result
Thx for help.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If I’m understanding correctly, you want to match a url that has a word in it and pass that to your route, but the word could be in multiple languages.
By default an Asp.net MVC Route will work with any language. For example a route like this:
Will match a url like “/controller/action/one-more-трудно-получить-result”. The ID parameter will hold the value “one-more-трудно-получить-result”.
If you are looking to limit the route so it only matches words (no numbers) from any language then here is your regex:
And here is how you would route this:
The \p{L} will match any kind of letter from any language. The \p{M} will match any character intended to be combined with another character (e.g. accents, umlauts, enclosing boxes, etc.). This route will match a url like “/controller/action/one-more-трудно-получить-result” but not “/controller/action/one-more-трудно-по12341лучить-result”.
Just an FYI the \p{N} is used to match any number, \p{P} is for punctuation, and \p{C} if for invisible control characters and unused code points.
Resources:
http://www.regular-expressions.info/unicode.html