开发者

value extraction using regular expressions

开发者 https://www.devze.com 2023-03-29 09:03 出处:网络
I 开发者_Python百科have a text file that contains commands in this formatex:>> call << I want to use a regular expression to extract \"call\" ..

I 开发者_Python百科have a text file that contains commands in this format ex:>> call <<

I want to use a regular expression to extract "call" .. how could be done?

Regex ComandStart = new Regex(">>", RegexOptions.Multiline);
Regex ComandEnd = new Regex("<<", RegexOptions.Multiline);              


create the regex:

var regex = new Regex(@"ex:>>([a-z]+)<<");

then extract if match :

var match = regex.Match("ex:>>call<<");
var yourString = match.Groups[1].Value; //yourString = "call" here


If you're on Windows, you could use Notepad++ with the Regex helper plugin for testing your regex's

This expression works fine for me:

/ex:\>\>(.*)\<\</

No idea about c# specifically, sorry

0

精彩评论

暂无评论...
验证码 换一张
取 消