A regular expression is a logical formula for string operations. It uses predefined characters and combinations of these specific characters to form a "rule string ", this "rule string" is used to express a filtering logic for strings.
Given a regular expression and another string, we can achieve the following goals:
1. Whether the given string conforms to the filtering logic of the regular expression (called "match ");
2. You can use a regular expression to obtain the desired part from the string.
Regular expressions are characterized:
1. Strong flexibility, logic, and functionality;
2. You can quickly implement complex string control in an extremely simple way.
3. It is difficult for new contacts.
Because regular expressions are mainly applied to text, they are used in various text editors, from the famous editor EditPlus to the large editor such as Microsoft Word and Visual Studio, you can use regular expressions to process text content.
The posix standard of regex (Regular Expression) complies with the unix platform. gnu has made a lot of extensions to regex to make regex easier to use, but not all platforms support gnu extensions.
The Mac OS x platform only supports the posix standard, but does not support the gnu extension. Therefore, when running the gnu extension script on Mac OS X platform, compatibility issues may occur.
For example, the \ s extension that matches all white spaces is gnu extension. To match all white spaces on Mac OS X, use [[: space:].
Below are some common posix expressions corresponding to GNU extensions:
\ W-[[: alnum:] _]
\ W-[^ [: alnum:] _]
\ S-[[: space:]
\ S-[^ [: space:]