Vira e mexe eu tenho que fazer um parse de um método VB. Finalmente achei uma forma elegante é simples de fazê-lo.
string Content = [A string que será usada como base];
string myRegExp = "(?<=Sub)(.*?)(?=End Sub)"; // A expressão para o Regular Expression
Regex r = new Regex(myRegExp, RegexOptions.Singleline); // Execução
Match m = r.Match(Content); // Et Voilà!! And done!
Mostrando postagens com marcador Regular Expression. Mostrar todas as postagens
Mostrando postagens com marcador Regular Expression. Mostrar todas as postagens
terça-feira, 8 de abril de 2014
Parse, Regular Expression
sexta-feira, 10 de maio de 2013
Exemplo simples de regular expression (CSharp, Regular Expression)
Neste exemplo coloquei no pattern de busca uma chave.
ArrayList getMatches(string pText)
{
ArrayList arrMatches = new ArrayList();
string stringToTest = pText;
const string patternToMatch = "}";
Regex regex = new Regex(patternToMatch, RegexOptions.Compiled);
MatchCollection matches = regex.Matches(stringToTest);
foreach (Match match in matches)
{
arrMatches.Add(match.Index);
}
return arrMatches;
}
O que este código faz
1 - Cria um array
2 - Utiliza um patter de busca "{". Serão procuradas todas as chaves do texto passado.
3 - Utilizou-se o regular expression para procurar as chaves.
4 - Populou-se o array iniciado no começo.
Pronto, acabou.
ArrayList getMatches(string pText)
{
ArrayList arrMatches = new ArrayList();
string stringToTest = pText;
const string patternToMatch = "}";
Regex regex = new Regex(patternToMatch, RegexOptions.Compiled);
MatchCollection matches = regex.Matches(stringToTest);
foreach (Match match in matches)
{
arrMatches.Add(match.Index);
}
return arrMatches;
}
O que este código faz
1 - Cria um array
2 - Utiliza um patter de busca "{". Serão procuradas todas as chaves do texto passado.
3 - Utilizou-se o regular expression para procurar as chaves.
4 - Populou-se o array iniciado no começo.
Pronto, acabou.
Assinar:
Postagens (Atom)