The experience of using regular time to get matching strings in VBScript

Source: Internet
Author: User
Vbscript| 's Experience |

It's a bit more cumbersome to use in VBScript than in JavaScript. JavaScript can be used without creating a RegExp object, but it is not available in VB. and JavaScript can use regexp.$1 to get pattern matching, but not in VB. Need to use another object and a collection: Matchcollection,match

One example is as follows:

Suppose there is a string with such a

Strnor= "; Northsnow: The snow in the northern, Csdn: The largest developer network in China; CRC: Changchun Rail Bus Co., Ltd.;

String contains a lot of substrings, substring is used; (semicolon) split open, each substring also divided into two parts, the first part of the logo or English name, the latter part of the Chinese name or description. Find the following instructions based on the given identity how do you do that? That's the problem we're going to solve in this case:

The code is as follows:

Dim ostr
Ostr= "; Northsnow: The snow in the northern, Csdn: The largest developer network in China; CRC: Changchun Rail Bus Co., Ltd.;
function GetName (ooid)
Dim objRegExp, Rematchcol,rematch,resubmatch
Dim rValue
Set objregexp=new REGEXP
Objregexp.pattern= ";(" & Ooid & "):([^;] *)"
Objregexp.ignorecase=true
Objregexp.global=true
Set rematchcol= objregexp.execute (OSTR) ' executes the query and returns a match to a matching set
If Rematchcol.count>0 Then
Set rematch = Rematchcol (0) ' places the first matching string in a matching object
Set resubmatch = Rematch.submatches ' Returns a child matching set
If Resubmatch (0) =ooid Then
Rvalue=resubmatch (1)
Else
Rvalue= ""
End If
Else
Rvalue= ""
End If
Getname=rvalue
End Function
Response. Write getName ("Northsnow")

Thank you for reading this article, have comments or suggestions please participate in the comments, or email author, author email:northsnow@163.com



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.