ripgrep

Usually, the shortcut key for Xcode is Shift + Command + O, and then shift+ Command + J to quickly locate the directory of the file you just found. What if we’re not using Xcode? How do I find it?

Ripgrep is a tool written by Rust that supports regular expression search for files and strings.

The installation

brew install ripgrep
Copy the code

Use specific click links

Rg < the key string to search for, and the regular expression > < a file or a directory >

rg fast README.md
Copy the code

Regular expression

Special characters

$matches the end of the input string

() marks the start and end of a subexpression

* Matches the preceding subexpression zero or more times

+ matches the preceding subexpression one or more times

Matches any single character except newline \n

[Marks the beginning of a bracketed expression

? Matches the preceding subexpression zero or once, or indicates a non-greedy qualifier

\ Marks the next character as an or special character, or a literal character, or a backreference, or an octal escape

^ Matches the start of the input string unless used in a square bracket expression, in which case it indicates that the set of characters is not accepted

{marks the beginning of a qualifier expression

| indicate a choice between the two

qualifiers

*

  • Matches the preceding subexpression zero or more times. For example, zo* matches “z” and “zoo”. * is equivalent to {0,}

+

  • Matches the previous subexpression one or more times. For example, ‘zo+’ matches “zo” and “zoo”, but not “z”. + is equivalent to {1,}

?

  • Matches the preceding subexpression zero or once. For example, “do (es)?” Matches “do”, “does”, and “doxy”. ? Equivalent to {0, 1}

{n}

  • N is a non-negative integer. Match certain n times. For example, ‘o{2}’ does not match the ‘O’ in “Bob”, but does match two o’s in “food”

{n,}

  • N is a non-negative integer. At least n times. For example, ‘o{2,}’ does not match the ‘O’ in “Bob”, but matches all o’s in “foooood”. ‘o{1,}’ is equivalent to ‘o+’. ‘o{0,}’ is equivalent to ‘o*’

{n,m}

  • Both m and n are non-negative integers, where n <= m. At least n times and at most m times are matched. For example, “o{1,3}” will match the first three o’s in “fooooood”. ‘o{0,1}’ is equivalent to ‘o? ‘. Note that there can be no Spaces between commas and numbers

locator

^ Matches the position at the beginning of the input string. If the Multiline property of the RegExp object is set, ^ will also match the position after \n or \r

$matches the position at the end of the input string. If the Multiline property of the RegExp object is set, $will also match the position before \n or \r

\b Matches a word boundary, the position between a word and a space

\B Non-word boundary matching

application

In iOS, for example, the nickname identification function consists of Chinese characters, letters, or numbers

- (BOOL)isHaveIllegalCharacter {NSString *regex = @"[a-zA-Z\u4e00-\u9fa5][a-zA-Z0-9\u4e00-\u9fa5]+";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];

    if(! [pred evaluateWithObject:self]) {return YES;
    } else {
        returnNO; }}Copy the code

The password must contain a combination of uppercase and lowercase letters and numbers, and cannot contain special characters. The password must be between 8 and 10 characters in length.

^ (? =.*\d)(? =.*[a-z])(? =. * [a-z]). 8, 10 {} $

The string can only be Chinese

^[\u4e00-\u9fa5]{0,}$

The value is a string of 26 letters, digits, and underscores

^\w+$

Checking E-mail addresses is a regular check statement for E-mail address compliance

[\w!# $% & '* + / =? ^ _ ` {|} ~ -] + (? :\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(? :[\w](? :[\w-]*[\w])? \.) +[\w](? :[\w-]*[\w])?
Copy the code

Check the ID card number. The following is the regular check of the ID card number. 15 or 18

15:

^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$

18:

^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$

Date verification in YYYY-MM-DD format with flat leap years taken into account

^ (? : (? ! 0000) [0-9] {4} - (? : (? : 0 | [1-9] [0-2] 1) - (? : 0 [1-9] [0-9] | | 1 2 [0 to 8]) | (? : 0 [9] 13 - | [0-2] 1) - (? 30) : 29 | | (? : 0 [13578] 1 [02]) - 31) | | (? : [0-9] {2} (? : 0 [48] | [2468] [048] | [13579] [26]) | (? : 0 [48] | [2468] [048] | [13579] [26]) 00) - 02 - $29)

Amount check, accurate to 2 decimal places

^ [0-9] + (. [0-9] {2})? $

Verify the mobile phone number. The following is the regular expression for mobile phone numbers starting with 13, 15, and 18 in The country. (The first two digits can be extended according to the current domestic collection number)

^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$