ba5tz

regex Email dan No HP

Nov 6th, 2020 (edited)
497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function NoHP(MyRange As Range)
  2. Dim regEx As Object
  3. Dim allMatches
  4.  
  5. Set regEx = CreateObject("VBScript.RegExp")
  6. With regEx
  7.     .Pattern = "([\d+]+)"
  8.     .IgnoreCase = True
  9.     .Global = True
  10. End With
  11.  
  12. Set allMatches = regEx.Execute(MyRange)
  13. If allMatches.Count > 0 Then
  14.     NoHP = allMatches(0)
  15. Else
  16.     NoHP = ""
  17. End If
  18. End Function
  19.  
  20. Function Email(MyRange As Range) As String
  21. Dim regEx As Object
  22. Dim Patternnya As String
  23. Dim allMatches
  24.  
  25. Patternnya = "[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-zA-Z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"
  26.  
  27. Set regEx = CreateObject("VBScript.RegExp")
  28. With regEx
  29.     .Pattern = Patternnya
  30.     .IgnoreCase = True
  31.     .Global = True
  32. End With
  33.  
  34. Set allMatches = regEx.Execute(MyRange)
  35. If allMatches.Count > 0 Then
  36.     Email = allMatches(0)
  37. Else
  38.     Email = ""
  39. End If
  40. End Function
Add Comment
Please, Sign In to add comment