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

[µo°Ý] ¤å¦r¼Æ­È©î¤À

[µo°Ý] ¤å¦r¼Æ­È©î¤À

Dear ¦U¦ì¥ý¶i¤j¤j :

¦³¤@¤å¦r¼Æ­È­åªRªº°ÝÃD¡A¦V¤j®a¨D±Ð

¤@¤å¦r ­^¼Æ²VÂø    ¤ñ¦p AAA120CCC4DC   ·Q±q¥ª°_¥h°£­^¤å¦r¨ú 120 ¼Æ­È
¤å¦r¦ê¨S¦³©T©wªø«×«e«á³£¦³¥i¯à¦³­^¤å¼Æ¦r¡AVBA¤¤¥i¦³¤è¦¡¥i¨ú±o¨ä­È¡A
©Î¬O¥i¦³²[¼Æ¤è¦¡¤]¥i¹F¦¨
ÁÂÁ«ü¾É
½Ð¦h¦h«ü±Ð

¦^´_ 1# ayubbs
  1. Sub Test()
  2.     Dim oReg As Object, s As String, sGet As String
  3.     s = "AAA120CCC4DC"  '120
  4.     's = "120CCC4DC"    '120
  5.     's = "AAA120"       '120
  6.    
  7.     Set oReg = CreateObject("vbscript.regexp")
  8.     With oReg
  9.         .Pattern = "^[^\d]*(\d+).*$"
  10.         If .Test(s) Then
  11.             sGet = .Replace(s, "$1")
  12.             MsgBox "¨ú¥X¤å¦r¬°: " & sGet
  13.         Else
  14.             MsgBox "¦r¦ê¤£²Å¦X«ü©w®æ¦¡"
  15.         End If
  16.     End With
  17. End Sub
½Æ»s¥N½X
ªí¹F¤£²M¡BÃD·N¤£©ú½T¡B¨SªþÀɮ׮榡¡B¨S¦³°Q½×°ÝÃDªººA«×~~~~~~¥H¤W·R²ö¯à§U¡C

TOP

¦^´_ 2# stillfish00


    ÁÂÁ¤j¤j«ü¾É~¤p©f²Â©å¹ê¦b¤£¤F¸Ñ³o­ÓÀ³¥Î¬O«ç»ò¹F¦¨ªº

.Pattern = "^[^\d]*(\d+).*$"        
sGet = .Replace(s, "$1")

¦pªG ¦r¦ê¤º®e ¬°   ¤¤­^¤å¦r²V²Å¸¹¤Î  ¨ì   ¦p¬°    "¨ú¦r¦ê125acd"   ¥i¨ú±o125ªº­È  
¦ý­Y¬°"¨ú¦r¦ê12.5acd" ¥i§_¨ú±o§t¤p¼Æ³¡¥÷  ¦p12.5  ¦r¦ê¦r¼Ë

ÁÂÁÂ~¼W¥[ª¾ÃÑ
½Ð¦h¦h«ü±Ð

TOP

¥»©«³Ì«á¥Ñ stillfish00 ©ó 2015-3-13 13:48 ½s¿è

¦^´_ 3# ayubbs
¬Oªº¡A­n¬Ý§A©Ò¿×ªº¼Æ¦r¥]§t­þ¨Ç®æ¦¡
«e­±¨Ò¤l§ìªº¬O¥u¦³ 0~9ªº³sÄò¼Æ¦r
¦]¬°§A»¡©úªº±Ô­z¥u¥]§t³oºØ¼Æ¦r
¦pªG­n§t¤p¼ÆÂI

.Pattern = "^[^\d]*(\d+(\.\d+)?).*$"   

´N¥i¥H¤F
ªí¹F¤£²M¡BÃD·N¤£©ú½T¡B¨SªþÀɮ׮榡¡B¨S¦³°Q½×°ÝÃDªººA«×~~~~~~¥H¤W·R²ö¯à§U¡C

TOP

¥»©«³Ì«á¥Ñ stillfish00 ©ó 2015-3-13 14:51 ½s¿è

¦^´_ 4# stillfish00
.Pattern = "^[^\d]*(\d+(\.\d+)?).*$"

²³æ¸ÑÄÀ¤@¤U¡A¥¿«hªí¥Üªk(¥¿³Wªí¹F¦¡)¬O¥Îpattern³]¸m³W«h
¨Ó§PÂ_¤å¦r¤¤¬O§_¯à§ä¨ì¤@¬q¬O²Å¦X³W«hªº¦r¦ê
¶}ÀYªº^ªí¥Ü¤Ç°t¤å¦r¶}ÀY
µ²§Àªº$ªí¥Ü¤Ç°t¤å¦rµ²§À
©Ò¥H¬OÀˬd¤å¦r¬O§_§¹¥þ²Å¦X
¨ä¤¤ \d ªí¥Ü 0©Î1©Î2©Î....©Î9 ªº¦r¤¸
[^\d] ªí¥Ü«D 0©Î1©Î2©Î....©Î9 ªº¦r¤¸
. ªí¥Ü¥ô·N¦r¤¸
\.  ¤~¬Oªí¥Ü¤p¼ÆÂI
* ªí¥Ü«e¤@­Ó¦r¤¸­«½Æ0¦¸~­«½ÆµL­­¦h¦¸
+ ªí¥Ü«e¤@­Ó¦r¤¸­«½Æ1¦¸~­«½ÆµL­­¦h¦¸
? ªí¥Ü«e¤@­Ó¦r¤¸­«½Æ0¦¸ ©Î ­«½Æ1¦¸
( ) ¬A¸¹¦³¨âºØ·N¸q,  
¤@¬O¬°¤FÀx¦s¬A¸¹¤Ç°tªº¤å¦r¨ì¤º³¡ªº¤l¦r¦ê , ¤]´N¬O«á¨Ó¥i¥Î"$1"´£¨ú¥X¨Ó
¤@¬O·í( )«á­±¬Ò¤W¹³* + ? ®É ­«½Æªº¤£¬O¤@­Ó¦r¤¸¦Ó¬O¬A¸¹¤ºªº¦r

¦]¦¹   "^[^\d]*(\d+(\.\d+)?).*$"   ¸ÑÄÀ·N«ä´N¬O
^  ¶}ÀY¬O
[^\d]*  ¹s­Ó©ÎN­Ó«D¼Æ¦r¤å¦r
\d+   1­Ó¥H¤W³sÄò¼Æ¦r
(\.\d+)?   ¤p¼ÆÂI±µ1­Ó¥H¤W³sÄò¼Æ¦r , ©Î¨S¦³
.*   ¥ô·N¦h­Ó¦r¤¸ , ©Î¨S¦³
$  µ²§À

¤j­P¬O³o¼Ë.........
·íµM³oÃä¥u¬O¤@¨Ò¦Ó¤w¡Apattern¥i¥H¦³«Ü¦hºØ¥Îªk
¸Ô²Ó»yªk­n¦Û¤v¥h§ä¥¿«hªí¥Üªk¨Ó¬Ý

¥t¤@ºØ¼gªk:
  1. Sub TestGGG()
  2.     Dim oReg As Object, s As String, oMatch As Object, sGet As String
  3.     s = "¨ú¦r¦ê12.3acd"  '12.3
  4.     's = "120CCC4DC"    '120
  5.     's = "AAA120"       '120
  6.    
  7.     Set oReg = CreateObject("vbscript.regexp")
  8.     oReg.Pattern = "\d+(\.\d+)?"
  9.     Set oMatch = oReg.Execute(s)
  10.    
  11.     If oMatch.Count > 0 Then
  12.         sGet = oMatch(0)
  13.         MsgBox "¨ú¥X¼Æ¦r¬°: " & sGet
  14.     Else
  15.         MsgBox "§ä¤£¨ì¼Æ¦r"
  16.     End If
  17. End Sub
½Æ»s¥N½X
ªí¹F¤£²M¡BÃD·N¤£©ú½T¡B¨SªþÀɮ׮榡¡B¨S¦³°Q½×°ÝÃDªººA«×~~~~~~¥H¤W·R²ö¯à§U¡C

TOP

¦^´_ 5# stillfish00

ÁÂÁ¤j¤j»¡©úªº¶W¸Ô²Óªº
·|¦n¦n¾Ç²ß´ú¸Õ¡A¤º®e¬Ý¨Ó¤£Â²³æ­n§âÅÞ¿èµ¹¥¦§Ë²M·¡¤~¯à¬¡¥Î¡C

ÁÂÁÂ~¤S¦h¾Ç¨ì¤F¨Çª¾ÃÑ
½Ð¦h¦h«ü±Ð

TOP

½Ð±Ðstillfish00¤j !  
±z´£¨Ñªº¤èªk¬O¤£¬O¥u¯à¥Î¦b ­^¤å¦r¥À»P¼Æ¦r²V©Mªº¦r¦ê¡A ­Y¬O¼Æ¦r»P¤¤¤å¦r²V¦Xªº¦r¦ê¬O§_¦³¹ïÀ³Pattern¥i¥H¨Ï¥Î?

TOP

        ÀR«ä¦Û¦b : ¦a¤WºØ¤Fµæ¡A´N¤£©öªø¯ó¡F¤ß¤¤¦³µ½¡A´N¤£©ö¥Í´c¡C
ªð¦^¦Cªí ¤W¤@¥DÃD