我需要匹配文字并在比赛中获取文字。
例如我的文字是HTML格式,我将在下面用作示例
java -jar schemaSpy_5.0.0.jar -t pgsql -db `db_name` -host 127.0.0.1 -u `db_user` -p admin -o ./schemaspy -dp postgresql-9.4-1206-jdbc4.jar -s public -noads
匹配案例:
案例1(如果中间是匹配词):<p>Do not forget the error handling, I don't exactly know what happens if it wants to replace an occurence and can't find it</p>
<p>Edit: If you have multiple entries which should be replaced, loop the replace part until it will not be able to replace anymore then it will throw an error you can catch to continue</p>
结果:occurence
案例2(如果在第一个单词中匹配单词):I don't exactly know what happens if it wants to replace an occurence and can't find it
结果:Do not
案例3(如果文本中最后一个单词中的匹配词):Do not forget the error handling, I don't exactly know what happens if it wants to replace an occurence and can't find it
结果:to continue
如果它是文本之间的单词,它应该在单词周围得到文本。 如果匹配单词是第一个单词,那么它应该从第一个单词本身获取文本
如果匹配是最后一个单词,则从匹配的最后一个单词之前获取文本。
REGEX If you have multiple entries which should be replaced, loop the replace part until it will not be able to replace anymore then it will throw an error you can catch to continue
只匹配单词,我怎么能让我们在匹配的关键字周围说10 -15个单词。
这是否可以使用Regex
答案 0 :(得分:2)
案例1:
([\w\s']+(?:occurence)[^<]+)|>((?:occurence)[^<]+)|[^>]+(?:occurence)<
输出:
我不知道如果要替换出现会发生什么 并且找不到它
案例2:
([\w\s']+(?:Do not)[^<]+)|>((?:Do not)[^<]+)|[^>]+(?:Do not)<
输出:
不要忘记错误处理,我不知道如果发生了什么 它想要替换出现而无法找到它
案例3:
([\w\s']+(?:to continue)[^<]+)|>((?:to continue)[^<]+)|[^>]+(?:to continue)<
输出:
编辑:如果您有多个应该被替换的条目,请循环播放 更换零件,直到它将无法再更换,然后它将 抛出一个错误,你可以抓住继续
限制词语
案例1:
>(Do not(?:\s(?:[\w']+),?){0,100})|((?:\s(?:[\w']+)){0,100}\s?Do not(?:\s(?:[\w']+),?){0,100})|((?:\s(?:[\w',]+)){0,100}\s?Do not)<
案例2:
>(occurence(?:\s(?:[\w']+),?){0,100})|((?:\s(?:[\w']+)){0,100}\s?occurence(?:\s(?:[\w']+),?){0,100})|((?:\s(?:[\w',]+)){0,100}\s?occurence)<
案例3:
>(continue(?:\s(?:[\w']+),?){0,100})|((?:\s(?:[\w']+)){0,100}\s?continue(?:\s(?:[\w']+),?){0,100})|((?:\s(?:[\w',]+)){0,100}\s?continue)<