我想从特殊前缀中选择句子:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Room : MonoBehaviour {
public ClassB classBTestInstance = new ClassB(3);
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
public class ClassB {
public ClassB(int testNum) {
Debug.Log("hello " + testNum);
}
}
我尝试删除(re-find (re-pattern (str "(?<=" "\\+" "+:=)" ".+")) "++:= test test")
=> " test test"
头部的空格。所以我将其改为:
test test
但是此代码有效:
(re-find (re-pattern (str "(?<=" "\\+" "+:=\\s*)" ".+")) "++:= test test")
=>nil
实际上,(re-find (re-pattern (str "(?<=" "\\+" "+:=\\s)" ".+")) "++:= test test")
=> "test test"
之前不仅有一个空格(也许没有空格),我不知道为什么test test
能够正常工作但\\s
不能。{1}}。
此代码中发生了什么?我怎么能解决它?
答案 0 :(得分:1)
编辑: 如果你有一个幸运的引擎,可以进行可变宽度的外观扫描
你可以通过坚持一个负面的预测来强迫它发挥作用
使用(?<=\++:=\s*)(?!\s).+
对于其他引擎:
\s*
可以匹配可变数量的空格
\++
可以匹配可变数量的加号。
除了Dot-Net正则表达式引擎外, DO NOT 允许在后向断言中使用可变宽度。
所以这个(?<=\++:=\s*)
会抛出一个错误,即不会编译。
我不确定 don't work
...
通常的做法是捕捉你需要的东西,然后参考。
\++:=\s*(.+)
** Grp 0 - ( pos 0 , len 14 )
++:= test test
** Grp 1 - ( pos 5 , len 9 )
test test