【发布时间】:2017-09-20 18:03:00
【问题描述】:
我想删除字符串中的所有字符,除了:
-
-或_或. -
A直通Z -
a直通z -
0到9 - 空间
在 linux 命令行上,使用 sed 我会这样做:
$ echo "testing-#$% yes.no" | sed 's/[^-_.a-zA-Z0-9 ]//g'
输出:
testing- yes.no
如何使用 PARSE 在 Red 语言中实现相同的效果?我看了看:
- http://www.rebol.com/docs/core23/rebolcore-15.html#section-1
- http://rebol-land.blogspot.in/2013/03/rebols-answer-to-regex-parse-and-rebol.html
- http://ross-gill.com/page/Beyond_Regular_Expressions
但是,我无法对其进行编码。我试过了:
>> parse "mystring%^&" [#a - #z #A - #Z #0 - #9]
== false
>> parse "mystring%^&" [#a-#z#A-#Z#0-#9]
== false
【问题讨论】:
-
如果你想删除一些字符,记得使用
trim。trim/with "testing-#$% yes.no" "-#$%." == "testing yesno"