Looking for regex: soft hyphen or not a word character
I am looking for a regex yielding to characters which are not word-characters n开发者_开发知识库or a soft hyphen (U+00AD).
This will give me characters which are not word-characters:
((?=\W).)
But what about the soft hyphen character? What is the correct regex?
You can do this:
[^\w\u00AD]
(NOT a word or soft hyphen)
I created a quick and dirty last_symbol()
function:
function last_symbol(str) {
var result = str.match(/([^\w\u00AD])[\w\u00AD]*$/);
return (result == null) ? null : result[1]; }
last_symbol('hello') // null
last_symbol('hell!') // '!'
last_symbol('hell!o$') // '$'
You can use \u00AD
to match the unicode soft hypen character, so you should be able to negate this expression and combine it with \W
to match characters which are not a word character and not a soft hyphen.
[^\u00AD\w]+
Use regex /\x{AD}/u
to match soft hyphens in PHP!
精彩评论