正则表达式可忽略注释行 [英] Regular Expression to ignore commented lines
问题描述
我正在尝试创建正则表达式来解析一段代码.
这是我的代码snipett
Method1( 100 ,variable1)
@"
从上面的表达式中,我正在提取不同的数据.
但是在某些情况下,我有机会发表评论
如下所示
Method1( 100 ,variable1)' 解决方案
"
从上面的表达式中,我正在提取不同的数据.
但是在某些情况下,我有机会发表评论
如下所示Method1( 100 ,variable1)' 字符串模式= @" ^ \ s * Method1 \ s * \(\ s *(\ d +)\ s *,\ s *([^)] *)\)(\ s * \'.*)?\ s *
I am trying to create regular expression to parse a piece of code.
here is my code snipett
Method1(100,variable1)
@"^(?\Method1)\((?\d+),\s(?\w+)\)$"
from above expression i am extracting different data.
But i some cases there are chances to commented lines
like below
Method1(100,variable1) 'method1 is called here
so how what should i add in my above regular expression to ignore strings after the '')'' close bracket
"
from above expression i am extracting different data.
But i some cases there are chances to commented lines
like belowMethod1(100,variable1) 'method1 is called here
so how what should i add in my above regular expression to ignore strings after the '')'' close bracket
You can try the regular expression''/\*([^*]|[\r\n]|(\*([^/]|[\r\n])))*\*/''to ignore comments in the code
Here it is :
string pattern = @"^\s*Method1\s*\(\s*(\d+)\s*,\s*([^)]*)\)(\s*\'.*)?\s*
这篇关于正则表达式可忽略注释行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!