除下列单词外,我想匹配所有单词:
1) any-random-word
2) any-random-word/
3) any-random-word/123
4) any-random-word/abcdef
这样跟随类似的词就可以匹配了。
1) any-random-word123
2) any-random-word(any non-word character other than '/')123
2) any-random-wordabcdef
4) any-random-word(any non-word character other than '/&
我希望排除包含特定单词或短语的匹配。例如,我如何才能只匹配第1行和第3行?\b单词边界并不像我预期的那样直观地工作。
foo.js # match
foo_test.js # do not match
foo.ts # match
fun_tset.js # match
fun_tset_test.ts # do not match
更新
我想排除的是在扩展名前显式以_test结尾的字符串。起初,我有类似于[^_test]的东西,但这也排除了这些字符的任何组合(如第3行)。
我和git-bash一起在win 10工作。我有一大组文件,所有这些文件都没有扩展名。但是,我意识到"File“类型的文件是html文件。为了选择这些,我尝试了:
$ find -type "File"
find: Arguments to -type should contain only one letter
如何选择类型为“File”的文件(不考虑扩展名)
我正试着在一个文件中找到一个确切的单词。这个单词是myServer,我试图在其中查找它的文件内容是:
This is myServer and it is cool
This is myServer-test and it is cool
这是我各种尝试的结果:
grep '^myServer$' test-file.txt
grep -Fx myServer test-file.txt
--> no results
grep -w myServer test-file.txt
grep -w myServer test-file.txt
grep '\<
我想接受包含这些字符的单词:'.:?!',我尝试了这个模式:r'*(.|:|?|!)*',但是不起作用。
我是如何通过使用python re来实现这一点的。
我想运行的代码如下:
import re
pattern = r'*(.|:|?|!)*'
word = '.Flask'
match = re.match(pattern, word)
if match:
print('yes')
例如,我想接受这些词:'.flask','flask.','!flask'
我正在尝试过滤以某个单词开头并以该单词结尾的单词。我有一些文本数据,例如:
data <- c("No comment", "Nothing", "No clue", "No", "No", "I have no clue", "Noe")
现在,我想要检测以no开头和结尾的句子。我试过了
str_detect(data, "^No", negate = FALSE)
但显然也检测到了句子1,3和令人惊讶的句子7。
我不知道如何告诉R仅当且仅当句子以"N
一般来说,我对正则表达式是个新手,我开始阅读更多关于它们的内容,所以请注意:-)
我要查找所有以my("或my('开头的单词。单词本身可以包含下划线、字符、数字,基本上可以包含任何字符。但它应该以")或')结尾。
因此,我尝试了以下方法:
Pattern.compile("_(\"(.*)\")"); // for underscores first, instead of my
和
Pattern.compile("(my)(\"(.*)\")");
但这也给了我其他的东西,我看不出我为什么以及在