Thariama Thariama - 1 year ago 121
Javascript Question

Looking for regex: soft hyphen or not a word character

I am looking for a regex yielding to characters which are not word-characters nor a soft hyphen (U+00AD).

This will give me characters which are not word-characters:


But what about the soft hyphen character? What is the correct regex?

Answer Source

You can do this:


(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$') // '$'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download