Golang 의 RegExp 정규 표현 식 사용법 안내
------------------------------------------------------------
Golang       
------------------------------------------------------------
  :
------------------------------
  :
        .                           ,     s = true,        
        [   ]              “   ”      ,“   ”      
        [^   ]             “   ”      ,“   ”      
        \  Perl           “Perl ”      ,“Perl ”      
        \  Perl           “Perl ”      ,“Perl ”      
        [:ASCII  :]         “ASCII ”      ,“ASCII ”      
        [:^ASCII  :]        “ASCII ”      ,“ASCII ”      
        \pUnicode         “Unicode ”      (    ),“Unicode ”      
        \PUnicode         “Unicode ”      (    ),“Unicode ”      
        \p{Unicode  }       “Unicode ”      ,“Unicode ”      
        \P{Unicode  }       “Unicode ”      ,“Unicode ”      
------------------------------
  :
        xy                xy(x      y)
        x|y               x   y (     x)
------------------------------
  :
        x*                     x,      (  )
        x+                     x,      (  )
        x?                     x,      (  )
        x{n,m}            n   m   x,      (  )
        x{n,}             n      x,      (  )
        x{n}               n   x
        x*?                    x,      (   )
        x+?                    x,      (   )
        x??                    x,      (   )
        x{n,m}?           n   m   x,      (   )
        x{n,}?            n      x,      (   )
        x{n}?              n   x
------------------------------
  :
        (    )                 ,      (   )
        (?P    )         ,          (   )
        (?:    )                (   )
        (?  )                      ,   ,              
        (?  :    )             ,   ,             
              :
        xyz  (   xyz   )
        -xyz (   xyz   )
        xy-z (   xy   ,    z   )
                :
        i                     (    false)
        m                  :  ^   $             ,       (    false)
        s                .    
 (    false)
        U                   :   x*   x*?      (    false)
------------------------------
    :
        ^                   m=true      ,           (m     false)
        $                   m=true      ,           (m     false)
        \A                      ,   m   
        \b                   
        \B                    
        \z                      ,   m   
------------------------------
    :
        \a                      (    \x07)
                         :           \b      ,   \b          ,
                            \x08      。
        \f                      (    \x0C)
        \t                    (    \x09)
        
                      (    \x0A)
        \r                      (    \x0D)
        \v                    (    \x0B)
        \123              8            (    3    )
        \x7F              16           (    3    )
        \x{10FFFF}        16           (    10FFFF  )
        \Q...\E           \Q   \E      ,          
        \\                  \
        \^                  ^
        \$                  $
        \.                  .
        \*                  *
        \+                  +
        \?                  ?
        \{                  {
        \}                  }
        \(                  (
        \)                  )
        \[                  [
        \]                  ]
        \|                  |
------------------------------
   “     ”  “   ”   :
        [\d]                (    \d)
        [^\d]                (    \D)
        [\D]                 (    \D)
        [^\D]               (    \d)
        [[:name:]]        “ASCII  ”   “   ”  (    [:name:])
        [^[:name:]]       “ASCII  ”    “   ”  (    [:^name:])
        [\p{Name}]        “Unicode  ”   “   ”  (    \p{Name})
        [^\p{Name}]       “Unicode  ”    “   ”  (    \P{Name})
------------------------------------------------------------
  :
------------------------------
“   ”    (“   ”  “Perl ”、“ASCII ”、“Unicode ”):
    x                        
    A-Z                      (      )
    \                Perl 
    [:ASCII  :]        ASCII 
    \p{Unicode    }  Unicode  (   )
    \pUnicode        Unicode  (   )
------------------------------
“Perl  ”    :
    \d                (    [0-9])
    \D                 (    [^0-9])
    \s                (    [\t
\f\r ])
    \S                 (   [^\t
\f\r ])
    \w                  (    [0-9A-Za-z_])
    \W                   (    [^0-9A-Za-z_])
------------------------------
“ASCII  ”    
    [:alnum:]           (    [0-9A-Za-z])
    [:alpha:]         (    [A-Za-z])
    [:ascii:]      ASCII     (    [\x00-\x7F])
    [:blank:]            (    [\t ])
    [:cntrl:]           (    [\x00-\x1F\x7F])
    [:digit:]         (    [0-9])
    [:graph:]           (    [!-~])
    [:lower:]           (    [a-z])
    [:print:]            (    [ -~]     [ [:graph:]])
    [:punct:]           (    [!-/:-@[-   {-~])
    [:space:]          (    [\t
\v\f\r ])
    [:upper:]          (    [A-Z])
    [:word:]           (    [0-9A-Za-z_])
    [:xdigit:]     16      (    [0-9A-Fa-f])
------------------------------
“Unicode  ”    ---   :
    C                 -  -          (other)
    Cc                            (control)
    Cf                              (format)
    Co                           (private use)
    Cs                             (surrogate)
    L                 -  -          (letter)
    Ll                            (lowercase letter)
    Lm                            (modifier letter)
    Lo                            (other letter)
    Lt                         (titlecase letter)
    Lu                            (uppercase letter)
    M                 -  -          (mark)
    Mc                            (spacing mark)
    Me                            (enclosing mark)
    Mn                           (non-spacing mark)
    N                 -  -          (number)
    Nd                           (decimal number)
    Nl                            (letter number)
    No                            (other number)
    P                 -  -          (punctuation)
    Pc                           (connector punctuation)
    Pd                         (dash punctuation)
    Pe                         (close punctuation)
    Pf                         (final punctuation)
    Pi                         (initial punctuation)
    Po                          (other punctuation)
    Ps                         (open punctuation)
    S                 -  -          (symbol)
    Sc                            (currency symbol)
    Sk                            (modifier symbol)
    Sm                            (math symbol)
    So                            (other symbol)
    Z                 -   -        (separator)
    Zl                            (line separator)
    Zp                           (paragraph separator)
    Zs                           (space separator)
------------------------------
“Unicode  ”    ---   :
    Arabic                      
    Armenian                     
    Balinese                    
    Bengali                     
    Bopomofo                      
    Braille                   
    Buginese                   
    Buhid                       
    Canadian_Aboriginal           
    Carian                      
    Cham                       
    Cherokee                    
    Common                     ,           
    Coptic                      
    Cuneiform                   
    Cypriot                      
    Cyrillic                    
    Deseret                     
    Devanagari                
    Ethiopic                     
    Georgian                     
    Glagolitic                   
    Gothic                     
    Greek                     
    Gujarati                     
    Gurmukhi                     
    Han                       
    Hangul                    
    Hanunoo                     
    Hebrew                      
    Hiragana                   (  )
    Inherited                         
    Kannada                     
    Katakana                   (  )
    Kayah_Li                    
    Kharoshthi                   
    Khmer                      
    Lao                        
    Latin                      
    Lepcha                      
    Limbu                      
    Linear_B                B     (   )
    Lycian                      
    Lydian                      
    Malayalam                     
    Mongolian                  
    Myanmar                    
    New_Tai_Lue                 
    Nko                     Nko 
    Ogham                      
    Ol_Chiki                    
    Old_Italic                   
    Old_Persian                 
    Oriya                       
    Osmanya                      
    Phags_Pa                    
    Phoenician                  
    Rejang                     
    Runic                         
    Saurashtra                    (    )
    Shavian                     
    Sinhala                     
    Sundanese                  
    Syloti_Nagri                 
    Syriac                      
    Tagalog                     
    Tagbanwa                      
    Tai_Le                      
    Tamil                       
    Telugu                      
    Thaana                      
    Thai                      
    Tibetan                   
    Tifinagh                    
    Ugaritic                     
    Vai                        
    Yi                        
------------------------------------------------------------
  :
     [a-z]         ,     []     - ,    -    []       ,   [-a-z]   [a-z-]
      []        :\f、\t、
、\r、\v、\377、\xFF、\x{10FFFF}、\\、\^、\$、\.、\*、\+、\?、\{、\}、\(、\)、\[、\]、\|(          )
                ,           ,“    ”      $1、${1}、$name、${name}    “     ”         。   $0        ,$1     1    ,$2     2    ,……。
    “     ”  $name    ,       ,name           ,  :$1x     ${1x},   ${1}x,   :$10     ${10},    ${1}0。
     $       ,    “    ”    $   ,    \$   。
               “Perl   ”,  “Perl   ” ,Go         “POSIX   ”,“POSIX   ”      “Perl  ”  ,     。
------------------------------------------------------------
//   
func main() {
	text := `Hello   !123 Go.`
	//          
	reg := regexp.MustCompile(`[a-z]+`)
	fmt.Printf("%q
", reg.FindAllString(text, -1))
	// ["ello" "o"]
	//           
	reg = regexp.MustCompile(`[^a-z]+`)
	fmt.Printf("%q
", reg.FindAllString(text, -1))
	// ["H" "   !123 G" "."]
	//          
	reg = regexp.MustCompile(`[\w]+`)
	fmt.Printf("%q
", reg.FindAllString(text, -1))
	// ["Hello" "123" "Go"]
	//           、     
	reg = regexp.MustCompile(`[^\w\s]+`)
	fmt.Printf("%q
", reg.FindAllString(text, -1))
	// ["  !" "."]
	//          
	reg = regexp.MustCompile(`[[:upper:]]+`)
	fmt.Printf("%q
", reg.FindAllString(text, -1))
	// ["H" "G"]
	//        ASCII   
	reg = regexp.MustCompile(`[[:^ascii:]]+`)
	fmt.Printf("%q
", reg.FindAllString(text, -1))
	// ["  !"]
	//          
	reg = regexp.MustCompile(`[\pP]+`)
	fmt.Printf("%q
", reg.FindAllString(text, -1))
	// ["!" "."]
	//             
	reg = regexp.MustCompile(`[\PP]+`)
	fmt.Printf("%q
", reg.FindAllString(text, -1))
	// ["Hello   " "123 Go"]
	//        
	reg = regexp.MustCompile(`[\p{Han}]+`)
	fmt.Printf("%q
", reg.FindAllString(text, -1))
	// ["  "]
	//           
	reg = regexp.MustCompile(`[\P{Han}]+`)
	fmt.Printf("%q
", reg.FindAllString(text, -1))
	// ["Hello " "!123 Go."]
	//    Hello   Go
	reg = regexp.MustCompile(`Hello|Go`)
	fmt.Printf("%q
", reg.FindAllString(text, -1))
	// ["Hello" "Go"]
	//       H   ,         
	reg = regexp.MustCompile(`^H.*\s`)
	fmt.Printf("%q
", reg.FindAllString(text, -1))
	// ["Hello   !123 "]
	//       H   ,         (     )
	reg = regexp.MustCompile(`(?U)^H.*\s`)
	fmt.Printf("%q
", reg.FindAllString(text, -1))
	// ["Hello "]
	//     hello   (     ),  Go       
	reg = regexp.MustCompile(`(?i:^hello).*Go`)
	fmt.Printf("%q
", reg.FindAllString(text, -1))
	// ["Hello   !123 Go"]
	//    Go.
	reg = regexp.MustCompile(`\QGo.\E`)
	fmt.Printf("%q
", reg.FindAllString(text, -1))
	// ["Go."]
	//        ,         (     )
	reg = regexp.MustCompile(`(?U)^.* `)
	fmt.Printf("%q
", reg.FindAllString(text, -1))
	// ["Hello "]
	//        ,     ,          
	reg = regexp.MustCompile(` [^ ]*$`)
	fmt.Printf("%q
", reg.FindAllString(text, -1))
	// [" Go."]
	//   “    ”      
	reg = regexp.MustCompile(`(?U)\b.+\b`)
	fmt.Printf("%q
", reg.FindAllString(text, -1))
	// ["Hello" "   !" "123" " " "Go"]
	//      1    4        ,   o       
	reg = regexp.MustCompile(`[^ ]{1,4}o`)
	fmt.Printf("%q
", reg.FindAllString(text, -1))
	// ["Hello" "Go"]
	//    Hello   Go
	reg = regexp.MustCompile(`(?:Hell|G)o`)
	fmt.Printf("%q
", reg.FindAllString(text, -1))
	// ["Hello" "Go"]
	//    Hello   Go,    Hellooo、Gooo
	reg = regexp.MustCompile(`(?PHell|G)o`)
	fmt.Printf("%q
", reg.ReplaceAllString(text, "${n}ooo"))
	// "Hellooo   !123 Gooo."
	//    Hello   Go
	reg = regexp.MustCompile(`(Hello)(.*)(Go)`)
	fmt.Printf("%q
", reg.ReplaceAllString(text, "$3$2$1"))
	// "Go   !123 Hello."
	//        
	reg = regexp.MustCompile(`[\f\t
\r\v\123\x7F\x{10FFFF}\\\^\$\.\*\+\?\{\}\(\)\[\]\|]`)
	fmt.Printf("%q
", reg.ReplaceAllString("\f\t
\r\v\123\x7F\U0010FFFF\\^$.*+?{}()[]|", "-"))
	// "----------------------"
}
------------------------------------------------------------
 
  다음으로 전송:https://www.cnblogs.com/sunsky303/p/11051468.html
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.