Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
12
返回列表 发新帖
楼主: mxg825

[已解决]学习正则法,这代码应该怎么写。。。

[复制链接]
发表于 2011-9-1 14:37 | 显示全部楼层
还应该排除括号:
Function ns(rg)
    With CreateObject("vbscript.regexp")
        .Global = True
        .Pattern = "[^\d\.\*\/\+\-\^\(\)]"
        ns = Application.Evaluate(.Replace(rg, ""))
    End With
End Function
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
回复

使用道具 举报

发表于 2011-9-1 14:58 | 显示全部楼层    本楼为最佳答案   
回复 兰色幻想 的帖子
  1. Sub mxg()
  2.   MsgBox ns("正度0.5*0.8+(3/2)-1")
  3. End Sub
  4. Function ns(rg As Variant) As String
  5.     With CreateObject("vbscript.regexp")
  6.         .Global = True
  7.         .MultiLine = True
  8.         .Pattern = "[\u4e00-\u9fa5]+"
  9.         If .test(rg) Then
  10.             ns = Format(Application.Evaluate(.Replace(rg, "")), "0.00")
  11.         End If
  12.     End With
  13. End Function
复制代码

{:111:}因为PATTERN多写了一个^
回复

使用道具 举报

 楼主| 发表于 2011-9-1 16:46 | 显示全部楼层
.Pattern 值 一变 应万变!确实厉害!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-6-4 15:12 , Processed in 0.434349 second(s), 7 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表