Home > Software engineering >  For help: the end of the regular expression to extract text in the VBA
For help: the end of the regular expression to extract text in the VBA

Time:11-15

1. Type the
2. Type/manufacturer
3. Type/manufacturer/model
A general regular expressions, to extract the final text
Results:
1. Type the
2. The manufacturer is
3. Type

CodePudding user response:

Try this:

The \ w + $

CodePudding user response:

As always provide the regular expression solution:
 
Sub test ()
The Debug. Print getLast (" type ")
The Debug. Print getLast (" type/factory ")
The Debug. Print getLast (" type/manufacturer/model ")
End Sub

The Function getLast (strIn As String) As String
Dim TMP () As String
TMP=Split (strIn, "/")
GetLast=TMP (UBound (TMP))
End the Function

CodePudding user response:

If the abandon with three lines of code, then change to a line,
 
Sub test ()
The Debug. Print getLast (" type ")
The Debug. Print getLast (" type/factory ")
The Debug. Print getLast (" type/manufacturer/model ")
End Sub

The Function getLast (strIn As String) As String
GetLast=Split (strIn, "/"), UBound (Split (strIn, "/")))
End the Function

CodePudding user response:

reference crispy big ice cream on the second floor response:
, as usual, provide a regular expression solution:
 
Sub test ()
The Debug. Print getLast (" type ")
The Debug. Print getLast (" type/factory ")
The Debug. Print getLast (" type/manufacturer/model ")
End Sub

The Function getLast (strIn As String) As String
Dim TMP () As String
TMP=Split (strIn, "/")
GetLast=TMP (UBound (TMP))
End the Function

although the wrong topic, but it can be solved

CodePudding user response:

reference 4 floor qq_36344860 response:
Quote: refer to the second floor crispy big ice cream reply:
, as usual, provide a regular expression solution:
 
Sub test ()
The Debug. Print getLast (" type ")
The Debug. Print getLast (" type/factory ")
The Debug. Print getLast (" type/manufacturer/model ")
End Sub

The Function getLast (strIn As String) As String
Dim TMP () As String
TMP=Split (strIn, "/")
GetLast=TMP (UBound (TMP))
End the Function

although the wrong question, but can really solve


Simple logic to deal with it is not necessary to use regular expressions, after all in the regular expression engine is much more complicated logic, increase consumption, to which reference library, it is not necessary,
  •  Tags:  
  • VBA
  • Related