Ruby Regular Expression details and sample code _ruby topics

Source: Internet
Author: User
Tags html tags numeric regular expression

In the PP file for writing puppet, many of the regular expressions for Ruby are used and are commonly used as follows:

Regular expression:

[Codesyntax lang= "Ruby"]

{}: The number of repetitions (such as {4} indicates that the preceding repeat occurs exactly 4 times)
{m,n}: The preceding element appears at least m times, with a maximum of n times
[]: A range descriptor, such as a letter in a-Z range (for example, [A-z])
\w: Character or number, equivalent to [ 0-9a-za-z]
\w: Non-alphabetic or numeric
\s: [\t\n\r\f] null character, equivalent to [\t\n\r\f]
\s: non-null character
\d: [0-9] number, equivalent to [0-9]
\d: non-numeric characters
*: The preceding element appears 0 or more times
+: The preceding element appears 1 or more times
?: The preceding element appears up to 1 times
|: Matches the preceding or following expression
\b: Backspace (0x08) (only when the range descriptor is inside)
\b: Word boundary (word boundary)
\b: Non-word boundaries (when outside the range descriptor)

instance: [Codesyntax lang= "Ruby"]

=begin nonnegative
Integer (Positive integer +0): ^\d+$
positive integer: ^[0-9]*[1-9][0-9]*$
non positive integer (negative integer +0): ^ (-\d+) | ( 0+) $
26-letter string: ^[a-za-z]+$ a
string of numbers and 26 English letters: ^[a-za-z0-9]+$
e-mail address: ^[\w-]+ (\.[ \w-]+) *@[\w-]+ (\.[ \w-]+) +$
year-month-day:
Chinese characters: [\u4e00-\u9fa5]
double-byte characters (including Chinese characters): [^\x00-\xff]
HTML Tags:/<.*>.*<\/\1 >|<.*>\/>/
Account is legal (beginning of letter, allow 5-16 bytes, allow alphanumeric underline): ^[a-za-z][a-za-z0-9_]{4,15}$
phone number: (\d{3}-|\d {4}-)? (\d{8}|\d{7})?
Tencent QQ Number: ^[1-9]*[1-9][0-9]*$

Thank you for reading, I hope to help you, thank you for your support for this site!

Related Article

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.