Home > Software engineering >  Vb how to use regular expressions to put all in a few large section of the character is extracted 8
Vb how to use regular expressions to put all in a few large section of the character is extracted 8

Time:09-19

For example, such as the following (actual will have ten rows).
With VBCRLF I will split into array first and then loop with regular extraction in the members of each array is just the number eight (8 consecutive Numbers), how to write? (0) was not first. Many thanks!

 13254815. Zip 
13266389. Zip
. Zip13307259
40245707. Zip
The 13689101. Zip
. Zip13689148
13066677. Zip
13676976. Zip
Between the 13509642 _ in brief. The zip
13619150 _ number of higher learning in south part ii tongji, 7th edition. Zip
13628123 _ China manage blue book 2014. Zip
"Act the role of project instance tutorial" _13688619. Zip


Himself wrote a wrong: it's too dishes.
 
Private Sub Command84_Click ()
Dim ss As String
Ss=Clipboard. GetText
Text15=quss (ss)
End Sub


The Function quss (oo As String)
The Set regex3=CreateObject (" VBScript. RegExp ")
Regex3. IgnoreCase=True
Regex3. Global=True
Regex3. MultiLine=False
Regex3. The Pattern="^ 1-9] [\ d {7} $"
The Set Matches=regex3. Execute (oo)
For Each Match Matches In
Quss=quss & amp; Match. SubMatches (0)
Next
End the Function


There are unable to use or emeditor like regular directly extracted the figures?

CodePudding user response:

Is this?
[1-9] {8}

CodePudding user response:

With this line: [1-9] \ d {7}

If you want to strict point: (with it? ! : \ d) (1-9] \ d {7} (? ! D: \)
The number of its 7 digits number before and after

CodePudding user response:

Upstairs warrior regular right. But I can't write code, don't know how to extract.

Searched a js code, can be implemented using Emeditor, but every time to enter the regular, I think it directly, I don't know how to change? I put the original code of var _regex=prompt (" this program is used to extract the regular expression matching string, please enter a regular expression ", "[1-9] \ d {7}"); Rewritten to var _regex=[1-9] \ d {7}; It said error "invalid character"
There will be js warrior can help myself? Thank you very much!


/* ** according to enter a regular expression, extraction and matching string, and create a new document to display all matching string, 
* displayed each match is a single line
*
* @ author Guapo
* @ version v1.0
*/
GetText ();
The function getText ()
{
//var _regex=prompt (" this program is used to extract the regular expression matching string, please enter a regular expression ", "[1-9] \ d {7}");

Var _regex=[1-9] \ d {7};
Var regex=new RegExp (_regex, "gim");
Document. The selection. The SelectAll ();
Var textInCurrentDocument=document. The selection. The Text;
Var matchResultArray=textInCurrentDocument. Match (regex);
If (matchResultArray)
{
Var len=matchResultArray. Length;
Editor. NewFile ();
for(var i=0; i{
Document. Writeln (matchResultArray [I]);
}
}
The else
{
Alert (" found no matching string ");
}
}

CodePudding user response:

'this code by " regular testing tools> v1.1.43 "generated automatically, please direct call TestReg process
 Private Sub TestReg () 
Dim strData As String
Dim reg As Object
Dim matchs the As Object, I As an Integer, j As Integer
StrData="https://bbs.csdn.net/topics/13254815.zip" & amp; VbCrLf & amp; _
"13266389. Zip" & amp; VbCrLf & amp; _
". Zip13307259 "& amp; VbCrLf & amp; _
"40245707. Zip" & amp; VbCrLf & amp; _
"13689101.zip" & amp; VbCrLf & amp; _
". Zip13689148 "& amp; VbCrLf & amp; _
"13066677. Zip" & amp; VbCrLf & amp; _
"13676976. Zip" & amp; VbCrLf & amp; _
"Between 13509642 _ in the brief history of. Zip" & amp; VbCrLf & amp; _
"13619150 _ number of higher learning in south part ii tongji, 7th edition. Zip" & amp; VbCrLf & amp; _
"13628123 _ China principle blue book 2014. Zip" & amp; VbCrLf & amp; _
"" act the role of project instance tutorial" _13688619.zip
"The Set reg=CreateObject (" vbscript. RegExp ")
Reg. Global=True
Reg. The IgnoreCase=True
Reg. MultiLine=True
Reg. The Pattern="(? ! : \ d) (1-9] \ d {7} (? ! :
\ d)"The Set matchs=reg. The Execute (strData)
For I=0 To matchs. Count - 1
The Debug. Print the I + 1 & amp; ". "& amp; Matchs (I)
For j=0 To matchs (I) SubMatches. Count - 1
The Debug. Print "(" & amp; J + 1 & amp; ") "& amp; Matchs (I). SubMatches (j) & amp; "";
Next
If matchs (I). SubMatches. Count & gt; 0 Then the Debug. Print
Next
End Sub



Recommended to use this tool, in the blank space form 3 quick blow can generate vb6 code, copy can run, introduce address:
http://blog.csdn.net/sysdzw/article/details/6141844

CodePudding user response:

refer to the second floor sysdzw response:
with this line: [1-9] \ d {7}

If you want to strict point: (with it? ! : \ d) (1-9] \ d {7} (? ! D: \)
The number of its 7 digits number before and after the


As if the tail is digital will be extracted to

CodePudding user response:

reference 5 floor wowfiowow reply:
Quote: refer to the second floor sysdzw response:

With this line: [1-9] \ d {7}

If you want to strict point: (with it? ! : \ d) (1-9] \ d {7} (? ! D: \)
The number of its 7 digits number before and after the


As if the tail is digital will be extracted to
I didn't say I don't see why the tail is digital, he as long as 8 digit

CodePudding user response:

Just 8 digits means such as not 9 digits or 10 digits...
  • Related