我在Match m = Regex.Match
之後沒有輸出。我認爲它有一個問題。有人可以檢查代碼,如果可以的話。使用匹配正則表達式時沒有輸出
輸入alarm_text
樣子:
PRIO 1個WESTERSTRAAT 140 ENKHUIZEN Woning品牌4632 4651
我想要做的是分割字符串中四組: 「PRIO 1」,「 WESTERSTRAAT 140 ENKHUIZEN」, 「Woning品牌」, 「4632 4651」
using System;
using System.Text.RegularExpressions;
using System.Data.Odbc;
namespace pdw_db
{
internal class pdw_db
{
public pdw_db()
{
}
private static void databaseThis(string capcode, string melding, string korps, string streetName, string preText, string postText, string cars)
{
string[] strArray = new string[] { "insert into alarmeringen2010(capcode, desc1, department, melding, alerting, data1, voertuigen)values('", capcode, "','", melding, "','", korps, "','", streetName, "','", preText, "','", postText, "','", cars, "',);" };
string str = string.Concat(strArray);
OdbcConnection odbcConnection = new OdbcConnection("DSN=pdw_db");
try
{
OdbcCommand odbcCommand = new OdbcCommand(str, odbcConnection);
odbcConnection.Open();
OdbcDataReader odbcDataReader = odbcCommand.ExecuteReader();
while (odbcDataReader.Read())
{
Console.WriteLine(odbcDataReader.GetString(0));
}
odbcDataReader.Close();
}
finally
{
if (odbcConnection != null)
{
odbcConnection.Dispose();
}
}
}
private static void Main(string[] args)
{
if (args.Length > 2)
{
return;
}
else
{
string alarm_capcode, alarm_text, alarm_korps;
//kill qoutes in alarmering
args[1] = args[1].Replace("\"", "");
args[1] = args[1].Replace("\'", "");
args[1] = args[1].Replace("'", "");
args[2] = args[2].Replace("\"", "");
args[2] = args[2].Replace("\'", "");
args[2] = args[2].Replace("'", "");
alarm_capcode = args[0];
alarm_text = args[1];
alarm_korps = args[2];
Match m = Regex.Match(alarm_text, @"(.*\s)([A-Z]+.[0-9]+.[A-Z])(.*\s)([0-9].*\s)");
string preText = m.Groups[1].Value;
string streetName = m.Groups[2].Value;
string postText = m.Groups[3].Value;
string cars = m.Groups[4].Value;
databaseThis(alarm_capcode, alarm_text, alarm_korps, streetName, preText, postText, cars);
}
}
}
}
你爲什麼顯示我們這麼多不相關的代碼?只需提供輸入文本,所需的輸出和代碼與正則表達式。 –
你能描述一下文本應該如何分解嗎?很難從你的正則表達式中找出你正在尋找的實際模式。 – jimmyfever
preText = Prio 1 streetName = WESTERSTRAAT 140 ENKHUIZEN postText = Woning品牌 汽車= 4632 4651 – 810