Please tell me how to extract the next line of the search string from the regular expression of VBS (with a new line).

Asked 1 years ago, Updated 1 years ago, 90 views

(Note) Search for the specified string by regular expression.
https://msdn.microsoft.com/ja-jp/library/cc392389.aspx

Function RegExpTest (patrn, strng)
    Create the DimregEx, Match, Matches' variable.
    Create a Set regEx=New RegExp' regular expression.
    Set the regEx.Pattern=patrn' pattern.
    regEx.IgnoreCase=True 'Uncase sensitive.
    regEx.Global=True' Set to search the entire string.
    Run the 'Set Matches=regEx.Execute(strng)' search.
    Repeat for For Each Match in Matches' Matches collection.
        RetStr = RetStr & "The location where a matching string was found is: "
        RetStr=RetStr&Match.FirstIndex&".The matching string must be "
        RetStr = RetStr&Match.Value&"." &vbCRLF
    Next
    RegExpTest=RetStr
End Function
'      012    34        567    89        012    34        567    89        0    12 
mySTR="IS1"&vbCrLf&"is2"&vbCrLf&"IS3"&vbCrLf&"is4"&vbCrLf&"5"&vbCrLf
msgbox (mySTR)
msgbox(len(mySTR))
MsgBox (RegExpTest("is., mySTR))
Could you tell me how to use the "regular expression of new line" to take out the ???5?????
MsgBox (RegExpTest("is." & vbCrLf, mySTR))
'---------------------------------------------------------------------------------------------
'IS1
'is2
'IS3
'is4
'5
'---------------------------------------------------------------------------------------------
'23
'---------------------------------------------------------------------------------------------
US>'The location where a matching string was found is 0.The matched string is IS1.
US>'The location where a matching string was found is 5.The matched string is 2 .
US>'The location where a matching string was found is 10.The matched string is IS3.
US>'The location where a matching string was found is 15.The matched string is 4 .

上記 Does the above function correspond to a new line?
②Is there only a way to use split?
Thank you for your cooperation.

regular-expression vbs

2022-09-30 14:24

1 Answers

How do I retrieve the next line of the search string?

Match.FirstIndex and Match.Value seem to be used, but there is also Match.Length.
Match.FirstIndex+Match.Length points to the next character in the search string.Since the regular expression pattern you are searching for ends with a new line with "is."&vbCrLf, it effectively points to the following line.


2022-09-30 14:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.