ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

¦p¦ó³]©wREGEXP PATTERN¤~¯à¨ú¥X¥¿½T¸ê®Æ©O¡H

¦U¦ì¤j¤j¦n¡G

  ¤p§Ì¦³¤G­Ó½d¨Ò¡A
²Ä¤@­Ó½d¨Ò¡G
Pattern = "\d+\s+(?=¤¸)."

¥i¥H¨ú¥X
100  ¤¸
8000  ¤¸
57  ¤¸

²Ä¤G­Ó½d¨Ò

.Pattern = "\d+\s+(?=¤è¤¸)."
¦ý¶È¨ú¥X
100  ¤è
8000  ¤è
57  ¤è

½Ð°Ý¦p¦ó¥i¦P®É¨ú¥X¦r¦ê"¤è¤¸"©O¡H


Sub aa()
    Dim regex As New RegExp
    Dim sr, mat, m
    sr = "abc  100  ¤¸  8000  ¤¸  57  ¤¸  efg"
    With regex
        .Global = True
        .Pattern = "\d+\s+(?=¤¸)."        
        Set mat = .Execute(sr)
        For Each m In mat
            Debug.Print m
        Next m
    End With
End Sub
Sub bb()
    Dim regex As New RegExp
    Dim sr, mat, m
    sr = "abc  100  ¤è¤¸  8000  ¤è¤¸  57  ¤è¤¸  efg"
    With regex
        .Global = True
        .Pattern = "\d+\s+(?=¤è¤¸)."
        
        Set mat = .Execute(sr)
        For Each m In mat
            Debug.Print m
        Next m
    End With
End Sub

TOP

ÁÂÁ¦U¦ì¤j¤j¡C
²Ä¤G¶µ¤w§ä¥X¤èªk¥i¸Ñ¨M¤F¡C
³]©w¦p¤U¡G
mPtn = "\d+\s+(?=PCS).{3}"

TOP

¥»©«³Ì«á¥Ñ stillfish00 ©ó 2013-8-23 09:23 ½s¿è

¦^´_ 11# dechiuan999
µLªÅ®æ¤]¯à¤Ç°t:
"\d+\s*¤¸"
"\d+\s*¤è¤¸"

TOP

¥»©«³Ì«á¥Ñ stillfish00 ©ó 2013-8-23 09:34 ½s¿è

¦^´_ 9# dechiuan999
¬ÛÃöºô¯¸
http://msdn.microsoft.com/en-us/library/1400241x(VS.85).aspx

³o½g¤]ÆZ¦³½ìªº
http://technet.microsoft.com/zh-tw/magazine/2008.05.heyscriptingguy.aspx

TOP

¦^´_ 14# stillfish00


    ÁÂÁ¤j¤j´£¨Ñ§óºë½oªº»yªk¡A
¤]¦P®É´£¨Ñ¾Ç²ßªººô¯¸¡C
¤p§Ì¹ï¤j¤j¦p¦¹¤F¸ÑREGEXP
EXPRESSªºÀ³¥Î¡C·Q¥²¤w¸g¬O
¥X¯«¤J¤Æªº¹Ò¬É¤F¡C
¤£ª¾¤j¤j¯à§_§Q¥Î¦¹¶é¦a¡A¶}ÅP
¦³ÃöREGEXP EXPRESS¾Ç²ß
«ü«n¡C
³o¼Ë¤]¯à´ç¤Æ§Ú­Ì³o¨Ç±ß½ú¡C
»¡¹ê¦b¡A¦n¨Ç¦~«e´N¦³¦V
OOBIRDª©¥D½Ð敎¹L¡C
¦Ó·í®É¹ê¦b¬O¤£±o¨äªù¦Ó¤J¡C
¦p¤µ¡A¤£·Q¦b¥b³~¦Ó°h¡A
¤]§Æ±æ¯à¼õ¹L³o¬q¾Ç²ßªºµh­W´Á¤F¡C

¯¬ºÖ¤j¤j
¨Æ¨Æ¶¶¤ß

TOP

¦^´_ 14# stillfish00

¤j¤j±z¦n¡G
¤p§Ì±q¤j²M¦­°_¡A´N¶}©l¾Ç²ß³]©w
¤j¤j¤§«e´£¨Ñ¤§»yªk¡A¨Ãµy¥[§ó§ï¤U¦C¦r¦ê¡C
¥u¬OmPtn¤§³]©wÁÙ¬OµLªk¦pÄ@¡A½Ð¤j¤j¦AÀ°
¤p§Ì¬Ý¬Ý¦p¦ó­×¥¿pattern©O¡H

mPtn = "PCE|\d+([.]?\d{0,2}|,\d{3}[.]?\d{0,2})*"


22  2 PCE   7,852.60  119,258,226.05
106  2 PCE   10,117,852  226.15
10  11 PCE   17,852  119,258,226.25
1080  118 PCE   1,117,852  119,258
109  1429 PCE   17,852.55  19,258
110  51511 PCE   17,852.70  119,258,226
11125  515 PCE   517,852  9,258,226.75
11.5 515 PCE 6.75 105.5

ÁÂÁ¤j¤j¡I

TOP

¦^´_ 16# dechiuan999


    ÁÂÁ¦U¦ì¤j¤j¡C
¤p§Ì¹ïpatternªº³]©w¤w¸Ñ¶}¤F¡C

mPtn = "PCE|\d([,}?\d{3}?[.]?\d{0,2})*"

TOP

¦^´_ 17# dechiuan999

Áö»¡patternªº³]­p¥»¨Ó´N¦³«Ü¦hºØ¡A¦ý§A³o [,}  ¥ª¥k¤£¹ïºÙ§Ú´N¬Ý¤£À´¤F¡C

­Y¬O¦Ò¼{¤p¼Æ¡A§Ú·|§ï¥Î "PCE|\d+(,\d{3})*(\.\d+)?"
¨ä¹ê³o¥D­n­n®Ú¾Ú§A¥i¯àªº¸ê®Æ¦³­þ¨Ç§Î¦¡¡A¬Ý§A­n¦hÄY®æ¤~¯à°÷§ìªº¥¿½T¡A
­Y¥i¯àªº¸ê®Æ¦r¦ê¥u¦³§A¼gªº¨º¨Ç§Î¦¡¡A¼eÃPÂI§ì¥Î "PCE|[0-9,.]+" ¬Æ¦Ü¥Î "\S+" ¤]¬O¥i¥Hªº¡C

³Ì¦n¬O¬Ý§Aªº«ä¸ô¡A¥Ñ«e¦Ó«á¡A¹³¤W­±­n¤Ç°t¤p¼ÆÂI«á¦Ó¥Îªº (\.\d+)?
«Ü®e©ö´N¯à²z¸Ñ¦¨ "¤@­Ó¤p¼ÆÂI«á­±±µ¤@­Ó¥H¤W¼Æ¦r¡A©Î³£¨S¦³"

¥t¥~¦³¨Çpattern¬Oµ¥®Äªº¡A©Ò¥H¼g¥X¨Ópattern¤£¦P¤]¬O¥¿±`ªº
¦p    \d   µ¥¦P  [0-9]
        +    µ¥¦P  {1,}
        *     µ¥¦P  {0,}
        ?     µ¥¦P  {0,1}
        \.    µ¥¦P  [.]

Á`¤§¥ý§¹¥þ²z¸Ñ¦U­Ó¯S®í¦r¤¸ªº·N¸q¡A¦A¹³°ï¿n¤ì¤@¼Ë°ï°_¨Ó¡A§Ú¤]¨S¬Æ»ò¯S§Oªº¤èªk¡C

TOP

¦^´_ 18# stillfish00


    ¤j¤j±z¦n¡G

  ¯uÅý¤j¤j¨£¯º¤F¡A
mPtn = "PCE|\d([,}?\d{3}?[.]?\d{0,2})*"
¹ê¦b¬O¦]¤p§Ì¸Õ¹LµL¼Æ¦¸¡A¤]³£¥¢±Ñ¦¬³õ¡C
¤Ï¦Ó¥´¿ù¤¤¬A¸¹«o¥i¥H逹¦¨¡A¤]¯u¬O©_ÂÝ©O¡H

¤j¤jªº»yªk²©ú§ã­n¡A¤]«Ü®e©ö²z¸Ñ¡C
¤p§Ì¤]·PÁ±z¦h¦¸¶}¥Ü¡A¤]Åý¤p§Ì¯à
¦A©¹«eÁÚ¶i¤@¤p¨B¡C
¤é«á¡A¤]§Æ±æ¤j¤j¯à¦h¦h敎»£¤p§Ì¤F¡C

·P®¦¤j¤j¡I

TOP

        ÀR«ä¦Û¦b : ¯à¥I¥X·R¤ß´N¬OºÖ¡A¯à®ø°£·Ð´o´N¬O¼z¡C
ªð¦^¦Cªí ¤W¤@¥DÃD