作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
示例文本(我已经突出显示了所需的 /
):
对[@Key=2]/
项目/
项目[Person/Name='Martin']/
日期
我正在尝试获取不在方括号内的每个正斜杠,任何精通 Regex 的人都可以帮助我解决这个问题吗?用途是:
string[] result = Regex.Split(text, pattern);
我已经用这段代码完成了,但想知道是否有一个更简单的 Regex 可以做同样的事情:
private string[] Split()
{
List<string> list = new List<string>();
int pos = 0, i = 0;
bool within = false;
Func<string> add = () => Format.Substring(pos, i - pos);
//string a;
for (; i < Format.Length; i++)
{
//a = add();
char c = Format[i];
switch (c)
{
case '/':
if (!within)
{
list.Add(add());
pos = i + 1;
}
break;
case '[':
within = true;
break;
case ']':
within = false;
break;
}
}
list.Add(add());
return list.Where(s => !string.IsNullOrEmpty(s)).ToArray();
}
最佳答案
使用 Regex.Matches
可能是比尝试使用拆分更好的方法。您无需指定要拆分的模式,而是尝试匹配所需的输出。这适用于基本情况:
string[] FancySplit(string input) {
return Regex.Matches(input, @"([^/\[\]]|\[[^]]*\])+")
.Cast<Match>()
.Select(m => m.Value)
.ToArray();
}
正则表达式的方法是查找以下序列:
[
、]
或/
的字符[
something ]
形式的序列,其中 something 允许包含 /
关于c# - 获取除方括号内的正斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10556282/
我有一个右下角倾斜的元素,我必须在其上放置一个盒子阴影。有时倾斜的 Angular 被徽章覆盖 - 我的问题不适用,如果是这样的话: 这是信息框及其边 Angular 的 (s)css 部分(还有更多
是否可以在纯 html/css 中创建类似下面的内容? 我想做这个响应式和全 (100%) 宽度(最大左 Angular 100 像素,右边最小 50 像素,类似的东西)。 最佳答案 您可以通过转换(
如何在 fabricjs 文本中为文本提供渐变或斜 Angular 效果?? http://fabricjs.com/fabric-intro-part-2/ 这里给出了形状和所有示例,我将其与文本绑
我用过: http://apps.eky.hk/css-triangle-generator/ 为彼此对 Angular 放置的两个不等边三 Angular 形生成 css: 左下三 Angular
我是一名优秀的程序员,十分优秀!