请协助进行模式匹配 [英] Please help with pattern matching

查看:119
本文介绍了请协助进行模式匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是的,我知道这完全是个n00b问题,所以我很感谢有人指出我正确的方向.

我正在尝试编写一个模式匹配脚本来设置变量.

模式是URL之一.我主要是想说:
如果文件在此文件夹树中,则3个文件夹的深度设置为Dim为x"

所以这就是我所拥有的

Yeah I know its a totally n00b question, so I appreciate someone pointing me in the right direction.

I am attempting to write a pattern matching script to set variable.

Pattern is one of a URL. I am trying to basically say:
"If file is in this folder tree 3 folders deep set Dim to x"

So here is what I have

Dim strBanner
If Request.ServerVariables("URL") like "*/vendors/[*]/[*]/
index.aspx*"  Then
    strBanner = Whatever


End If



我一直在寻找一种方法来捕获"//"之间的任何内容

感谢您的帮助!



I was looking for a way to catch anything in between "/ /"

Thanks for any help!

推荐答案

您正在寻找正则表达式.这是Expresso想到的:
You are looking for a regular expression. This is what Expresso came up with:
'  Imports System.Text.RegularExpressions

'  Regular expression built for Visual Basic on: Mon, Mar 14, 2011, 01:42:46 PM
'  Using Expresso Version: 3.0.3634, http://www.ultrapico.com
'
'  A description of the regular expression:
'
'  /vendors/
'      /vendors/
'  Any character that is NOT in this class: [/], any number of repetitions
'  /
'  Any character that is NOT in this class: [/], any number of repetitions
'  /index.aspx
'      /index
'      Any character
'      aspx
'
'

Public Dim regex As Regex = New Regex( _
      "/vendors/[^/]*/[^/]*/index.aspx", _
    RegexOptions.Singleline _
    Or RegexOptions.CultureInvariant _
    Or RegexOptions.IgnorePatternWhitespace _
    Or RegexOptions.Compiled _
    )


' This is the replacement string
Public Dim regexReplace As String = _
      "<Hello>"


'' Replace the matched text in the InputText using the replacement pattern
' Dim result As String = regex.Replace(InputText,regexReplace)

'' Split the InputText wherever the regex matches
' Dim results As String() = regex.Split(InputText)

'' Capture the first Match, if any, in the InputText
' Dim m As Match= regex.Match(InputText)

'' Capture all Matches in the InputText
' Dim ms As MatchCollection = regex.Matches(InputText)

'' Test to see if there is a match in the InputText
' Dim IsMatch As Boolean = regex.IsMatch(InputText)

'' Get the names of all the named and numbered capture groups
' Dim GroupNames As String() = regex.GetGroupNames()

'' Get the numbers of all the named and numbered capture groups
' Dim GroupNumbers As Integer() = regex.GetGroupNumbers()



如果将来要使用它们,请获取一份副本:它是免费的,并且可以帮助您解释,设计和检查正则表达式.希望我能写!



If you are going to use them in the future, get a copy: it''s free, and it helps explain, design, and check Regexes. I wish I''d written it!


这篇关于请协助进行模式匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆