我在C#程序中有以下正则表达式,并且难以理解它:
(?<=#)[^#]+(?=#)
Run Code Online (Sandbox Code Playgroud)
我会把它分解为我认为我理解的内容:
(?<=#) a group, matching a hash. what's `?<=`?
[^#]+ one or more non-hashes (used to achieve non-greediness)
(?=#) another group, matching a hash. what's the `?=`?
Run Code Online (Sandbox Code Playgroud)
所以这个问题我已经是?<=和?<组成部分.从阅读MSDN,?<name>用于命名组,但在这种情况下,尖括号永远不会关闭.
我?=在文档中找不到,搜索它真的很难,因为搜索引擎大多会忽略那些特殊的字符.
在给定CharSequence的情况下,标准Java库中是否有任何工具在O(1)时间内产生反转?
I guess this is "easy" to implement, just wondering whether it already exists. (I suspect the reason this is not offered is because the "easy" way would actually break multi-char code-points - but in many cases we know we are not dealing with those).
Thanks
Update Heh, it's a bit amusing that most thought this "impossible", good work guys! Well, actually it is (conceptually) trivial - pseudojava follows to make it clear:
class MyReverseString extends String { //of course …Run Code Online (Sandbox Code Playgroud) 我有这样的字符串String str = "la$le\\$li$lo".
我想拆分它以获得以下输出"la","le\\$li","lo".\ $是一个$转义所以它应该留在输出中.
但是,当我做 str.split("[^\\\\]\\$")ÿ得到"l","le\\$l","lo".
从我得到的我的正则表达式匹配$和i $然后删除.知道如何让我的角色回来吗?
谢谢