Home > Software engineering >  VB regular expressions
VB regular expressions

Time:10-06

Text to get such a message:
Xiao Ming 123456 18 male 12861114
123456 small red 24 women 50967799
123456 Chen 33 male 89282185
123456 the professor 19 women 88919680
How to put each sex, and finally the number of use regular expressions to obtain load the ListView respectively

CodePudding user response:

(male and female |)
(? & lt;=(male female) |) \ d +

CodePudding user response:


Regular expressions do not understand, only know simple statement,,

 
Dim ss (3) As String, sd (3, 2) As a String, the sr () As String, st As String
Dim I As Byte, sta As String

Ss (0)="123456 xiao Ming 18 male 12861114"
Ss: (1)="123456 little red 24 female 50967799"
Ss (2)="123456 Chen 33 male 89282185"
Ss (3)="123456 the professor 19 female 88919680"
Path=""
For I=0 To 3
The sta=IIf (InStr (1, ss (I), "male") & lt;> 0, "male" and "female")
The sr=Split (ss (I), the sta)
Sd (I, 0)=the sr (0)
Sd (I, 1)=sta
Sd (I, 2)=the sr (1)
Next

CodePudding user response:

'this code by " regular testing tools> v1.1.35 "generated automatically, please direct call TestReg process
 
Private Sub TestReg ()
Dim strData As String
Dim reg As Object
Dim matchs the As Object, the match As Object

StrData="xiaoming 18 male 12861114 https://bbs.csdn.net/topics/123456" & amp; VbCrLf & amp; _
"123456 little red 24 female 50967799" & amp; VbCrLf & amp; _
"123456 Chen 33 male 89282185" & amp; VbCrLf & amp; _
"The professor ([men]) 123456 (\ d +) 19 female 88919680"

The Set reg=CreateObject (" vbscript. RegExp ")
Reg. Global=True
Reg. The IgnoreCase=True
Reg. MultiLine=True
Reg. The Pattern="([men]) (\ d +)"
The Set matchs=reg. The Execute (strData)
For Each match matchs In
'Value
Debug. Print the match.The Debug. Print match. SubMatches (0)
Next
End Sub

Output:
1. The male 12861114
(1) male (2). 12861114
2. The female 50967799
(1). Female. (2). 50967799
3. The male 89282185
(1) male (2). 89282185
Female 88919680
4.(1). Female (2). 88919680

CodePudding user response:

  •  Tags:  
  • API
  • Related