删除string中的第一个数字前的任何字符和点/分号后的任何字符

如何增强此function,排除删除string中的第一个数字之前的任何字符以及之后的任何字符。 要么 : ? 例如:

GigabitEthernet0/3.210 --> 0/3 Serial6/2:0.100 --> 6/2 Serial6/6:0 --> 6/6 

Function: =REPLACE($A2,1,MIN(FIND({0,1,2,3,4,5,6,7,8,9},$A2&"0123456789"))-1,"")

你可以使用你已经得到的,并使用MIDfunction,而不是replace:

 =MID( $A1, MIN(FIND({0,1,2,3,4,5,6,7,8,9},$A1&"0123456789")), MIN(FIND({":","."},$A1&".:"))-MIN(FIND({0,1,2,3,4,5,6,7,8,9},$A1&"0123456789")) ) 

我会用正则expression式来解决这个问题 – 如果需要的话,可以在规则中提供更多的灵活性。

例如使用以下vba代码来公开REGEXP:

 Function RegExp(ByVal repattern As String, ByVal value As String, Optional occurrence = 1) ' does a regular expression search for "repattern" in string "value" ' returns the match ' or "" if not found RegExp = "" Dim RegEx As Object, RegMatchCollection As Object, RegMatch As Object ' create the RegExp Object with late binding Set RegEx = CreateObject("vbscript.regexp") With RegEx .Global = True 'look for global matches .Pattern = repattern End With counter = 1 Set RegMatchCollection = RegEx.Execute(value) For Each RegMatch In RegMatchCollection If counter = occurrence Then RegExp = RegMatch.value Exit For Else counter = counter + 1 End If Next Set RegMatchCollection = Nothing Set RegEx = Nothing End Function 

然后,您可以在工作表上使用公式=RegExp("[0-9][^\.:]*",A1)