我有以下要求,其中输入的文本必须匹配以下任何允许的字符列表,并获得所有不匹配reg exp模式的字符.
和特殊字符如:
我可以构建的正则表达式如下
/[^a-zA-Z0-9\ \.@\,\r\n*=:;\-_\&()\'\/]/g
Run Code Online (Sandbox Code Playgroud)
举个例子,比如说input='123.@&-_()/*=:/\';#$%^"~!?[]av'.无效字符是'#$%^"~!?[]'.
下面是我采用的方法来获得不匹配的字符.
1)构造如下所示的允许reg expn模式的否定.
/^([a-zA-Z0-9\ \.@\,\r\n*=:;\-_\&()\'\/])/g (如果这个reg exp是正确的,请更正吗?)
2) 使用替换功能获取所有字符
var nomatch = '';
for (var index = 0; index < input.length; index++) {
nomatch += input[index].replace(/^([a-zA-Z0-9\ \.@\,\r\n*=:;\-_\&()\'\/])/g, '');
}
so nomatch='#$%^"~!?[]' // finally
Run Code Online (Sandbox Code Playgroud)
但是这里的replace函数总是返回一个不匹配的字符.所以使用循环来获取所有.如果输入为100个字符,则它循环100次并且是不必要的.
有没有更好的方法让所有字符与下面的行中的reg exp模式不匹配.
非常感谢您对此提供任何帮助.
我对电子有疑问。
\n\n\n类型错误:无法读取未定义的属性“whenReady”
\n
我使用\n节点 14.0.1\n电子 10.1.2
\n我运行我的应用程序\n"electron:serve": "vue-cli-service electro:serve",
\n我的背景.js
\nconst { app, BrowserWindow } = require('electron')\nconst { server } = require('feature-server-core')\n\nserver.start();\n\nfunction createWindow () {\n // \xd0\xa1\xd0\xbe\xd0\xb7\xd0\xb4\xd0\xb0\xd0\xb5\xd0\xbc \xd0\xbe\xd0\xba\xd0\xbd\xd0\xbe \xd0\xb1\xd1\x80\xd0\xb0\xd1\x83\xd0\xb7\xd0\xb5\xd1\x80\xd0\xb0.\n\n const win = new BrowserWindow({\n width: 1400,\n height: 900,\n minWidth: 1280,\n minHeight: 800,\n closable: true,\n center: true,\n type: "tool",\n titleBarStyle: "hidden",\n })\n\n win.menuBarVisible = false;\n// \xd0\xb8 \xd0\xb7\xd0\xb0\xd0\xb3\xd1\x80\xd1\x83\xd0\xb6\xd0\xb0\xd0\xb5\xd0\xbc index.html \xd0\xb2 \xd0\xbf\xd1\x80\xd0\xb8\xd0\xbb\xd0\xbe\xd0\xb6\xd0\xb5\xd0\xbd\xd0\xb8\xd0\xb8.\n win.loadURL("google.com")\n}\n\napp.whenReady().then(() => {\n createWindow()\n\n app.on('activate', function () {\n // On macOS it's common to re-create …Run Code Online (Sandbox Code Playgroud) 我需要在B中找到"部分"存在于A中的所有字符串.
B = [ "Hello World!", "Hello Stack Overflow!", "Foo Bar!", "Food is nice...", "Hej" ]
A = [ "World", "Foo" ]
C = B.FuzzyCompare(A) // C = [ "Hello World!", "Foo Bar!", "Food is nice..." ]
Run Code Online (Sandbox Code Playgroud)
我一直在研究使用Levenshtein Distance Algorithm问题的"模糊"部分,以及迭代的LINQ.但是,A*B通常会导致超过15亿次比较.
我该怎么办呢?有没有办法快速"几乎比较"两个字符串列表?
让我们说:
class Bar:
pass
A = Bar()
while A:
print("Foo!")
Run Code Online (Sandbox Code Playgroud)
然后调用什么操作A来确定while循环?
我尝试过,__eq__但没有做太多.
以这段代码为例,我们有一个 Promise 调用一个会失败的函数,它应该将错误传递给 Promise 的 catch 方法。
从终端运行时它工作得很好。但是,当运行 vscode 时,它会在(1)处爆炸。
function failingFunc() {
let undef = undefined;
return undef.nope();
}
let promise = new Promise((resolve, reject) => {
resolve(failingFunc()); // (1) Explodes when run from vscode
});
promise.then(v => {}).catch((e: Error) => {
console.log(e.message); // (2) Prints when run from the terminal
});
Run Code Online (Sandbox Code Playgroud)
为什么是这样?
vscode 关于页面:
版本 1.14.2
提交 cb82feb
日期 2017-07-19T23:26:08.116Z
Shell 1.6.6
Renderer 56.0.2924.87
Node 7.4.0
目前我正在获取最新的,然后运行git status并解析输出,Your branch is up to date with 'origin/master'但这感觉就像一个黑客。
我已经研究过使用,git status --porcelain但这仅包括在系统上所做的文件更改,而不是在远程所做的更改。我不在乎实际进行了哪些更改,我只想知道是否存在任何更改(本地或远程)。
我将如何干净地实现这一目标?
我似乎在一个简单的javascript变量中存储SVG路径字符串时遇到了一些问题.这对我来说有点神秘,我无法找到任何指出为什么会发生这种情况的东西.
路径存储在单行字符串中,每端都有双引号.这是这个文件中唯一的东西,但当我尝试使用Raphael.js的字符串时,我收到了异常错误.思考?任何帮助非常感谢.
我想知道如何为传递给函数的所有参数运行一种方法并返回它们
这是我想要实现的示例:
const getAllData = (args) =>{
args.map((arg)=> useDispatch(arg))
}
return args
Run Code Online (Sandbox Code Playgroud)
并在另一个文件中调用它例如
const [var1,var2,var3] = getAllData()
Run Code Online (Sandbox Code Playgroud)
或者
const allVars = getAllData([var1,var2,var3])
Run Code Online (Sandbox Code Playgroud) 我是新来的.
所以我得到了这个工作:
foo :: String -> String
foo s = do replace "aoa" "a" s
Run Code Online (Sandbox Code Playgroud)
(键入foo "aoa"返回"a")
但是当我添加另一个替换:
foo :: String -> String
foo s = do replace "aoa" "a" s
replace "uou" "u" s
Run Code Online (Sandbox Code Playgroud)
(打字foo "aoa"退货"aoa")
一切都破了,我收到了这个警告:
A do-notation statement discarded a result of type ‘Char’
Suppress this warning by saying ‘_ <- replace "aoa" "a" s’
or by using the flag -fno-warn-unused-do-bind
Run Code Online (Sandbox Code Playgroud)
由于我不想压制警告,因此此错误消息对我没有任何意义.
我错过了什么?
Edit1
示例:
"aoaaoa" -> "aa" //Affected …Run Code Online (Sandbox Code Playgroud) 我有一系列汽车,我需要检查汽车是否存在于对象中。
const cars = ["mustang", 'sonata'];
const carsObj = {
ford: "mustang",
audi: 'r8',
tesla: 'model 3'
};
Run Code Online (Sandbox Code Playgroud)
到目前为止我所做的是检查,但我只知道如何使用对象中存在的数组中的第一个元素来执行此操作。如果可能,我正在寻找最快的方法。
carsObj[Object.keys(carsObj).find(key => carsObj[key] === cars[0])];
Run Code Online (Sandbox Code Playgroud)
这应该返回,mustang因为它在数组和对象中
我需要检查整个数组,而不是检查汽车 [0]。此外,阵列永远不会那么大。最多可能是 5 个元素。循环遍历对象的数组是否更好?
原谅原始问题.我想使用removeChild在HTML表中动态删除行.我按照这里的教程,仍然不能与我合作.这是我正在做的一个例子.我得到的错误是:
NotFoundError: Node was not found
Run Code Online (Sandbox Code Playgroud)
代码和脚本:
var currentRow=document.getElementById("row-2");
var table = document.getElementById("data-table");
table.removeChild(currentRow);Run Code Online (Sandbox Code Playgroud)
<html>
<head>
<meta charset="UTF-8">
</head>
<body id="body">
<table align="center" cellspacing=1 cellpadding=1 id="data-table" border=1 class="data-table">
<tr id="head" class="head">
<td class="head">A</td>
<td class="head">B</td>
<td class="head">C</td>
</tr>
<tr id="row-1" class="head">
<td class="head" id="col1-1">A1</td>
<td class="head" id="col2-1">B1</td>
<td class="head" id="col3-1">C1</td>
</tr>
<tr id="row-2" class="head">
<td class="head" id="col1-2">A2</td>
<td class="head" id="col2-2">B2</td>
<td class="head" id="col3-2">C2</td>
</tr>
</table>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
javascript ×7
node.js ×2
c# ×1
class ×1
compare ×1
electron ×1
exception ×1
git ×1
git-diff ×1
git-remote ×1
git-status ×1
haskell ×1
html ×1
linq ×1
loops ×1
operation ×1
parsing ×1
performance ×1
promise ×1
python ×1
python-3.x ×1
regex ×1
string ×1
svg ×1
while-loop ×1