相关疑难解决方法(0)

正则表达式'(?<=#)[^#] +(?=#)'如何工作?

我在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>用于命名组,但在这种情况下,尖括号永远不会关闭.

?=在文档中找不到,搜索它真的很难,因为搜索引擎大多会忽略那些特殊的字符.

regex lookahead lookbehind lookaround

20
推荐指数
1
解决办法
3521
查看次数

在O(1)中用Java反转一个字符串?

在给定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)

java string

19
推荐指数
3
解决办法
8305
查看次数

Java分裂正在吃我的角色

我有这样的字符串String str = "la$le\\$li$lo".

我想拆分它以获得以下输出"la","le\\$li","lo".\ $是一个$转义所以它应该留在输出中.

但是,当我做 str.split("[^\\\\]\\$")ÿ得到"l","le\\$l","lo".

从我得到的我的正则表达式匹配$和i $然后删除.知道如何让我的角色回来吗?

谢谢

java regex string split

16
推荐指数
1
解决办法
4928
查看次数

标签 统计

java ×2

regex ×2

string ×2

lookahead ×1

lookaround ×1

lookbehind ×1

split ×1