URL Friendly regular expression
Can anyone help me with regular expression for this: basically I have a search form and users type in whatever keywords they want to search and when a search button is clicked, the search keyword is appended to the url (see examples below). Note the keyword may contain any character.
Example 1 Search key: whatever you want URL: www.example.com/search/whatever+you+want/
Example 2 Search key: oh boy! what's going on? URL:开发者_StackOverflow社区 www.example.com/search/oh+boy!+what's+goin+on%3F
What regular expression can I use to capture all characters in the ASCII table between 32 to 126?
When I googled your question:
What regular expression can I use to capture all characters in the ASCII table between 32 to 126?
the second hit was a site on Regular Expressions with precisely the answer you want:
/[[:print:]]*/
assuming POSIX character classes are supported
If they aren't, you can use:
/[\x20-\x81]*/
In perl, at least, you could use something like:
/[\040-\176]/ # 32-126 in octal
However, whatever language you're using probably has a module / library for parsing URLs, and for reversing URL encoding in a more complete and correct way. It's probably better to use that than to use a regex. For example, perl has URI.
精彩评论