Nati323 Posted March 19, 2015 Share Posted March 19, 2015 (edited) in the reference http://www.w3schools.com/jsref/jsref_regexp_begin.asp, you say that b search for a word at the beginning and the end of a word, i try it but its not work on the end of a word, why is that? the code: var str = "Visit W3SchoolsW3"; var patt1 = /(bW3)/g; var result = str.match(patt1); document.getElementById("demo").innerHTML = result; And with a big B, its works but you say there that a big B search a match that is not at the start or end of a word: var str = "Visit W3SchoolsW3";var patt1 = /BW3/g;var result = str.match(patt1);document.getElementById("demo").innerHTML=result; Edited March 19, 2015 by Nati323 Link to comment Share on other sites More sharing options...
justsomeguy Posted March 19, 2015 Share Posted March 19, 2015 var patt1 = /(bW3)/g;You're telling it to match a character that is at the end of the word and followed by "W3". If it is followed by any letter then it is not at the end of the word, so that will never match. Link to comment Share on other sites More sharing options...
Nati323 Posted March 19, 2015 Author Share Posted March 19, 2015 (edited) i dont understand, i telling to regexp to search W3 at the end of the word, i have no any char at the end of the word except W3.... ? Edited March 19, 2015 by Nati323 Link to comment Share on other sites More sharing options...
justsomeguy Posted March 19, 2015 Share Posted March 19, 2015 My mistake on that last explanation, that wasn't correct. i telling to regexp to search W3 at the end of the wordNo, you're telling it to find a word boundary followed by W3. That will match at the beginning of a word, not the end. If you want to match the end then you need to look for W3 followed by a word boundary. Link to comment Share on other sites More sharing options...
Nati323 Posted March 19, 2015 Author Share Posted March 19, 2015 sorry my english sucks, i dont get the meaning of boundray, you can explain me with other word? and if you can give me code for example Link to comment Share on other sites More sharing options...
justsomeguy Posted March 19, 2015 Share Posted March 19, 2015 A boundary is a border. The meaning of b isn't an actual character, it will actually match the position between the start or end of a word and a space character. Think of it like the cursor blinking when you type. When you put the cursor at the beginning or end of a word, that is the position that b will match. So bW will match a word that begins with W (the match will be just before the W), and Wb will match a word that ends with W (the match will be just after the W). Link to comment Share on other sites More sharing options...
Nati323 Posted March 19, 2015 Author Share Posted March 19, 2015 i get it thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now