English 中文(简体)
为什么我以esh子取得奇怪的结果?
原标题:Why am I getting strange results with sed in eshell?

我对发现的结果感到困惑。 我把它简化为我可以打破的最简单的事情。

echo 1234567890abcdefghijklmnopqrstuvwxyz | sed  s/[:digit:]*/X/g 

我预计会得到:

Xabcdefghijklmnopqrstuvwxyz

我得出的产出是:

X1X2X3X4X5X6X7X8X9X0XaXbXcXeXfXhXjXkXlXmXnXoXpXqXrXsXuXvXwXxXyXzX

这不是我所期望的。 如果我改为:

echo 1234567890abcdefghijklmnopqrstuvwxyz | sed  s/[0-9]*/X/g 

我收到了:

XaXbXcXdXeXfXgXhXiXjXkXlXmXnXoXpXqXrXsXtXuXvXwXxXyXzX

这与我所期望的更接近。 我刚刚认识到,我没有在标准终点站有这个问题,而只是在地毯中。 我认为,它必须是个性化问题? 是否与单体编码相关? 我如何确定这一点,我如何解决这个问题?

最佳回答

认为reg果* 或以上前科(本案的果园)

正如“萨摩亚”所指出的,你需要[:数字:]。

因此,你可以减少第1X行的所有数字。

echo 1234567890abcdefghijklmnopqrstuvwxyz | sed  s/[[:digit:]][[:digit:]]*/X/g 
Xabcdefghijklmnopqrstuvwxyz

或所有数字的X代

echo 1234567890abcdefghijklmnopqrstuvwxyz | sed  s/[[:digit:]]/X/g 
XXXXXXXXXXabcdefghijklmnopqrstuvwxyz

如果这两项工作都没有,请问你需要什么产出。

我希望这一帮助。

问题回答

对第1号的答复是,特性类别[:数字:]本身需要包含在[]中,因此应当[[:数字:]。

仍在第二部分工作。

echo 1234567890abcdefghijklmnopqrstuvwxyz | sed  s/[0-9]+(.*)/X1/g 

[0-9]+ 相当于1234567890

页: 1





相关问题
Uncommon regular expressions [closed]

Recently I discovered two amazing regular expression features: ?: and ?!. I was curious of other neat regex features. So maybe you would like to share some tricky regular expressions.

regex to trap img tag, both versions

I need to remove image tags from text, so both versions of the tag: <img src="" ... ></img> <img src="" ... />

C++, Boost regex, replace value function of matched value?

Specifically, I have an array of strings called val, and want to replace all instances of "%{n}%" in the input with val[n]. More generally, I want the replace value to be a function of the match ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

Is it possible to negate a regular expression search?

I m building a lexical analysis engine in c#. For the most part it is done and works quite well. One of the features of my lexer is that it allows any user to input their own regular expressions. This ...

regex for four-digit numbers (or "default")

I need a regex for four-digit numbers separated by comma ("default" can also be a value). Examples: 6755 3452,8767,9865,8766,3454 7678,9876 1234,9867,6876,9865 default Note: "default" ...

热门标签