基本的要求是对给定的一个文本块进行关键字匹配,进行匹配的关键字是多个,而且可能非常多(成千上万),然后输出各个匹配到的关键字的位置。这可用用作关键字的高亮显示,当然也可用进行敏感词过滤。
参考linux命令行fgrep
输入一段文本,输出匹配到的关键字在输入文本中的位置。
例如,关键词列表:
package xsync | |
import ( | |
"context" | |
"fmt" | |
"runtime/debug" | |
) | |
// PanicGroup 并行执行多个协程并捕获所有 panic | |
// 使用方法如下 |
package main | |
import ( | |
"bytes" | |
"context" | |
"crypto/tls" | |
"encoding/binary" | |
"fmt" | |
"io" | |
"net" |
package main | |
import ( | |
"fmt" | |
"reflect" | |
"syscall" | |
"unsafe" | |
) | |
func a() int { |
env YACC=`brew --prefix bison`/bin/bison ./configure | |
--disable-all | |
--prefix=/tmp/php71 | |
--enable-phar | |
--enable-zip | |
--enable-tokenizer | |
--enable-json | |
--enable-posix | |
--with-libedit |
// compile with: gcc epoll-example-pipe.c | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/epoll.h> | |
#define MAXEVENTS 64 | |
int | |
main (int argc, char *argv[]) |
#!/usr/bin/env php | |
# you should add the following two line in you ovpn.conf | |
# route-noexec # donot let openvpn set local route | |
# route-up a.sh # run a.sh under ~/Library/Application Support/Tunnelblick/Configurations/bilibili.tblk/Contents/Resources | |
<?php | |
$env = $_ENV; | |
$route = []; |
# -*- coding: utf-8 -*- | |
import socket | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM); | |
s.connect(('192.168.8.20', 3000)) | |
m = '{"username":"test20","message":"测试"}' | |
mp = ( | |
"POST /notice HTTP/1.0\r\n" | |
"Content-Type:application/json\r\n" |
# curl -H "Content-Type: application/json" -d '{"username":"test20","message":"测试"}' http://192.168.8.20:3000/notice -v | |
* Hostname was NOT found in DNS cache | |
* Trying 192.168.8.20... | |
* Connected to 192.168.8.20 (192.168.8.20) port 3000 (#0) | |
> POST /notice HTTP/1.1 | |
> User-Agent: curl/7.35.0 | |
> Host: 192.168.8.20:3000 | |
> Accept: */* | |
> Content-Type: application/json | |
> Content-Length: 40 |
#include <stdio.h> | |
#include <stdlib.h> | |
#include "cJSON.h" | |
void doit(char *text) | |
{ | |
char *out;cJSON *json; | |
json=cJSON_Parse(text); | |
if (!json) {printf("Error before: [%s]\n",cJSON_GetErrorPtr());} |