duanniesui6391
2018-03-20 20:24
浏览 116
已采纳

RegEx:在分隔符之前或之后

Consider the following

use namespace;

class name impl... {

    use Trait;
}

How would I go about it, if I would like to extract either the use from before the class definition or the one after? Well in the above example it would be simple enough, but if it should also work on an actual code file with multiple use in both places and maybe not even grouped together, but with other things in between and also with all line chars removed?

It's easy enough to get them all, but I want it to either stop when it reaches the class or begin from the class. Just can't seam to get anything to work correctly.

Lines, comments and literals is stripped, so these should not be taken into consideration.

图片转代码服务由CSDN问答提供 功能建议

请考虑以下</ p>

 使用命名空间; 
 
class  name impl ... {
 
使用Trait; 
} 
 </ code> </ pre> 
 
 

如果我要提取<code,我将如何处理它? >在类定义之前使用</ code>或之后使用</ code>? 在上面的例子中它很简单,但如果它也应该在一个实际的代码文件上工作,在两个地方都有多个 use </ code>,甚至可能没有组合在一起,但是其他的东西也介于两者之间 删除所有行字符? </ p>

将它们全部搞定是很容易的,但是我希望它能够在到达课堂或从课程开始时停止。 只是不能缝合以使任何东西正常工作。 </ p>

删除了行,注释和文字,因此不应将其考虑在内。</ p> </ div>

2条回答 默认 最新

相关推荐 更多相似问题