在以下示例中,我需要在句号
的任一侧获得单词我正在使用这个正则表达式
Dim myRegex As New Regex("[^\w]+")
Dim mymatch As String() = myRegex.Split(currentField)
其中currentfield =以下3个样本之一
Contacts.Address2 as `Contact Address2`
Contacts.ContactID
CONCAT(Contacts.FirstName;;' ';;Contacts.LastName) as `Contact`
返回如下。
1-- Contacts,Address2,as,Contact和Address2不希望单词为。
2--联系人和ContactID这没关系。
3-- CONCAT,Contacts,FirstName,Contacts,LastName,as和Contact。
第3个这太多了,不想要CONCAT,或者联系。我只想要返回四个单词(句点前后的单词)联系人,名字,联系人和姓氏
如何编写正则表达式只能获取句点之前和之后的单词
答案 0 :(得分:1)
我会考虑匹配与<ul class="breadcrumb">
<li><a href="#">Home</a></li>
<li><a href="#">Equipment</a></li>
<li><a href="#">Category</a></li>
</ul>
输入:
split
这是一个例子,目前尚不清楚您对返回的结果的期望。
答案 1 :(得分:0)
我认为你只想拆分圆括号内,你对//TemplateA
{{props object.value}}
<span>{{:key}}</span>
<div>
{{for prop.set_of_data_1 ~prop=prop}}
{{include tmpl="TemplateB"/}}
{{/for}}
</div>
{{/props}}
//TemplateB
{{for ~prop.set_of_data_2}}
// This is working...
<span>{{:#parent.parent.data[#data.some_key]}}</span> //Accesing set_of_data_1
// But this doesn't...
{{if some_condition}}
<span>{{:#parent.parent.data[#data.some_key]}}</span> //Accesing set_of_data_1 inside IF (and I'm getting inside IF)
{{/if}}
{{/for}}
这个词不感兴趣。因此,我建议采用两步法:
as
正则表达式)\([^()]+\)
正则表达式)拆分原始字符串。\W+|\s*\bas\b\s*
答案 2 :(得分:0)
这是最终的工作程序,基于上面接受的答案
Public Sub Load_Field_List(FieldSTR As String, FieldType As String)
Dim t As New FileIO.TextFieldParser(New System.IO.StringReader(FieldSTR))
t.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
t.Delimiters = New String() {","}
Dim currentRow As String()
Dim dr As DataRow
Dim ColListSTR As String = loadeddataview.Tables(0).Rows(0).Item("ColumnList")
Dim ColListSTRArr As String() = ColListSTR.Split(",")
While Not t.EndOfData
Try
currentRow = t.ReadFields()
Dim currentField As String 'field string
For Each currentField In currentRow
Dim startName As Integer
Dim endName As Integer
Dim name As String
dr = fieldDT.NewRow
Dim isValid As Boolean = False
If currentField = "" Then 'make sure current field has data
isValid = False
ElseIf (Regex.IsMatch(currentField, "(\w+)\.(\w+)")) = True Then 'make sure current field has xxxx.yyyy pattern
Dim m As Match = Regex.Match(currentField, "(\w+)\.(\w+)") 'sets m to the first xxxx.yyyy pattern
dr("Table") = m.Groups(1).Value 'sets table column to table name xxxx
dr("Column Name") = "`" & m.Groups(2).Value & "`" 'sets column name to column yyyy enclosed in ` `
If ColListSTRArr.Contains(m.Groups(2).Value) Then 'checks columnlist str to see if column visible
dr("Show") = "True"
Else
dr("Show") = "False"
End If
' this section overrides column name if it was set using AS `zzzzz` statement
startName = currentField.IndexOf("`")
endName = currentField.IndexOf("`", If(startName > 0, startName + 1, 0))
If (endName > startName) Then
Dim mylength As Integer = currentField.Length
name = currentField.Substring(startName, endName - startName + 1)
dr("Column Name") = name 'set override columname
dr("Field") = currentField.Substring(0, startName - 4) 'sets field minus the " as 'ZZZZZ" above
If ColListSTRArr.Contains(currentField.Substring(startName + 1, endName - startName - 1)) Then 'dup may be able to remove
dr("Show") = "True"
Else
dr("Show") = "False"
End If
Else
dr("Field") = currentField 'sets field if there was no " as `ZZZZZZ`" in string
End If
If FieldType = "Field" Then 'sets the column linking field
dr("Linking") = "No Linking"
Else
dr("Linking") = FieldType
End If
End If
' commit changes
fieldDT.Rows.Add(dr)
fieldDT.AcceptChanges()
DataGridView3.DataSource = fieldDT
DataGridView3.ClearSelection()
Next
Catch ex As Microsoft.VisualBasic.
FileIO.MalformedLineException
MsgBox("Line " & ex.Message &
"is not valid and will be skipped.")
End Try
End While
End Sub