To continue with the basics of Python regular expressions, today’s special characters are “\s” and “\s”.

1. “\s” means matching space, and the matching mode “add \s oil” means there is space between the characters “add” and “oil”, as shown in the figure below.

You can see that there is a space between “add” and “oil” in the original string, which matches the matching condition, so the match is successful.

2. For better understanding, now change the original string to “add oil” with no Spaces between the characters and keep the matching mode unchanged, as shown in the figure below.

If no output is displayed, the match is not successful.

3. If there are multiple Spaces between “add” and “oil”, you only need to change “add \s oil” to “Add \ S + oil” in the matching mode, as shown below.

4. “\S” stands for the opposite meaning of “\S”, which means that any character that is not a space can be matched. Continue with the example in step 2, as shown below. Just change “\s” to “\s” in the matching pattern and leave everything else unchanged, as shown below.



You can see that the match is now successful.

5. Instead, change the original string to “oil”, with a space between the two characters, and the matching mode remains the same, as shown below.



If no output is displayed, the match is not successful.

6. Similarly, if you want to match multiple non-whitespace characters, just change “\S” to “\S+”, as shown below.



That’s all about the big “S” and the little “S”. Have you got it?