Home > Software engineering >  Regular expression error
Regular expression error

Time:11-20

Want to process the data to look like in the picture, the regular expression

Myreg2. The Pattern="\ s * (\ s +) award (\ s +)"
Myreg2. The Pattern="(\ w +) award (\ w +)"
Such as attendance third-class award second-class
Excel on the run in the face of the wrong, the following null values, but in the regular tester are both right, is this why?


Sub demo3 ()

Worksheets (1). Activate

Dim myreg1 As Object, myreg2 As Object, mymatch1 As Object
Dim mymc, mymatch2 As Object, k, mymatches1, mymatches2, mydata, I, j
I=6

The Set myreg1=CreateObject (" vbscript. Regexp ")
Myreg1. Global=True
Myreg1. The Pattern="name: \ s * (\ s +) \ s * awards: [[^;] +);"


The Set myreg2=CreateObject (" vbscript. Regexp ")
Myreg2. Global=True
Myreg2. The Pattern="\ s * (\ s +) award (\ s +)"
'myreg2. The Pattern="(\ w +) award) (\ w +"
Mydata=https://bbs.csdn.net/topics/Cells (1, 1). The Value

The Set mymatch1=myreg1. Execute (mydata)





For Each mymatches1 mymatch1 In

Mymc=mymatches1. Submatches (1)

The Set mymatch2=myreg2. Execute (mymc)



For Each mymatches2 mymatch2 In
MsgBox mymatches2. Submatches (0)


Next


Next

CodePudding user response:

\ w matching letters or Numbers or an underscore or equivalent to the Chinese characters' [^ A Za - z0-9 _] ',

May be the reason for the \ w cannot match Chinese;

CodePudding user response:

Just now I turn in the right content:
reference 1st floor milaoshu1020 response:
\ w matching letters or Numbers or an underscore or equivalent to the Chinese characters' [^ A Za - z0-9 _] ',


Note:
Can \ w matching characters depends on your operating system and application environment;
May be in the EXCEL VBA \ w cannot match Chinese reason;

CodePudding user response:

reference 1st floor milaoshu1020 response:
\ w matching letters or Numbers or an underscore or equivalent to the Chinese characters' [^ A Za - z0-9 _] ',

May be the reason for the \ w cannot match Chinese;


Diligent in Mickey Mouse, why not to be a moderator, VB plate is too desolate, need jerry to help
  •  Tags:  
  • VBA
  • Related