javascript - RegExp check on AT character -


i'm trying check if word in string, i've come far now. code below works perectly when word test or without special character behind it. want make check 1 character before string, character @ whenever string @test must match.

//this returns false not var str = "mr. @test has blue house"; var match = "@test"; var b = new regexp('\\b' + match + '(?:es|s)?\\b'); var n = b.test(str);     console.log('test 1 ' + n);   //this returns true var str = "mr. test! has blue house"; var match = "test"; var b = new regexp('\\b' + match + '(?:es|s)?\\b'); var n = b.test(str);     console.log('test 2 ' + n); 

\b used word boundaries, @ not word character. want should this:

\b@test(?:es|s)?\b 

which means there no word ending before @. (demo)


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -