I was learning regular expression in iOS, saw this tutorial:http://www.raywenderlich.com/30288/nsregularexpression-tutorial-and-cheat-sheet
It reads like this for \b:
\b matches word boundary characters such as spaces and punctuation. to\b will match the "to" in "to the moon" and "to!", but it will not match "tomorrow". \b is handy for "whole word" type matching.
\s matches whitespace characters such as spaces, tabs, and newlines. hello\s will match "hello " in "Well, hello there!".
what is the difference between \s and \b? when to use which?
\b is handy for "whole word" type matching -> Don't understand the meaning..
\b matches the boundary itself but not the boundary character (like a comma or period). It has no length in itself but can be used to find for example e in the end of a word.
For example in the sentence: "Hello there, this is one test. Testing"
e\b will match an e if it's at the end of the word (followed by a word boundary). Notice in the image below that the e in "test" and "Testing" didn't match since the "e" is not followed by a boundary.
\s on the other hand matches the actual white space characters (like spaces and tabs). In the same sentence it will match all the spaces between the words.
\b doesn't make much sense alone I showed to how to it as
e\b (above). The OP asked (in a comment) about what
e\s would match compared to
e\b to better explain the difference between
In the same string there is only one match for
e\s while there was two matches for
e\b since the comma is not a whitespace. Note that the
e\s match (image 3) includes the white space where as the
e\b match doesn't (image 1).