Wildcard and Regular Expression

Source: Internet
Author: User

Wildcards and regular expressions are easy to confuse. First, you must understand that the two are different. I personally think that Wildcards are used in shell commands (such as file name-related operations) in Linux, the regular expression is used to search and replace strings in text content. Wildcards are supported by the Linux system, while regular expressions are used in the vim editor or awk.ProgramThese text processing tools become powerful just because they support regular expressions.

  1. Wildcard
  • [A-Z] or [12]: match a single character or one of the characters listed in square brackets within a specified range.
  • [! 9]: does not match the characters listed in square brackets or a single character within the specified range.
  • *: Matches 0 or multiple characters.
  • ? : Matches any single character and cannot be a null character.
Because shell will change the character? [] * Special characters. Therefore, if you need to use these special characters in a command parameter, you should mark the parameter with single quotation marks or add escape characters \ before special characters \.
  1. Regular Expression
  • .: Match any single character. Is it in the function and wildcard? The symbols are the same.
  • [A-Z] or [12]: The function is the same as [] in the wildcard.
  • [^]: [!] In functions and wildcards Same.
  • *: The occurrence of the first character that matches the character 0 or multiple times.
  • ^: Match all rows starting with the specified regular expression.
  • $: Match all rows ending with a specified regular expression.

Note that special characters in [], for example, have lost their special meanings, are the same as common characters in [12] in square brackets.

Original article: http://www.cnblogs.com/sujz/archive/2011/12/14/2288164.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.