regex

Find if the sentence does not contains specific words

坚强是说给别人听的谎言 提交于 2021-01-01 08:11:02
问题 i have a regular expression which find if the sentence s contains specific words my query is: (?=.*hello)(?=.*hi)(?=.*hey).* but now i want to check if my sentence does not contains this words i have tried: (?=.*((?!hello).))(?=.*((?!hi).))(?=.*((?!hey).)).* but it does not works how should i build my query? Example: this query should return true when my sentence is: hi, how are you? and must return false when my sentence is: hi hello hey .. thanks in advance, 回答1: If the problem is to match

Regex to search for 5 words before and after a given word

早过忘川 提交于 2021-01-01 06:39:55
问题 I need to write an AS3 program to search for a certain "keyword" in the rss of certain blogs. I've written logic using String.indexOf() but this is EXTREMELY slow, and not scalable. I've been looking to write a regular expression which looks for the keyword, but also returns 5 words before and after the keyword (to show the context of the search result). I suppose overlapping matches can be ignored. I've come up with (?:[a-zA-Z'-]+[^a-zA-Z'-]+){0,5}keyword(?:[^a-zA-Z'-]+[a-zA-Z'-]+){0,5} The

.htaccess - get current url and pass part of it as variable

天大地大妈咪最大 提交于 2021-01-01 06:36:21
问题 I need to write optimized .htaccess rules. I had written like that and they are working RewriteEngine on RewriteRule ^city1-name-in-url/$ products.php?city=city1-name-in-url RewriteRule ^city2-name-in-url/$ products.php?city=city2-name-in-url RewriteRule ^city3-name-in-url/$ products.php?city=city3-name-in-url RewriteRule ^city4-name-in-url/$ products.php?city=city4-name-in-url And url for these rules are http://www.domain.com/global/city1-name-in-url/ I have to write these rules for 800

Linux文件查找介绍

人盡茶涼 提交于 2021-01-01 06:02:15
文件查找介绍: 在文件系统上查找符合条件的文件 locate:非实时查找,通过数据库进行查找,效率高,可用于查找比较固定的文件 依赖于/var/lib/mlocate/mlocate.db这个数据库文件,数据库时间点之前创建的文件是可以查找到的,而时间点之后新创建的文件就搜索不到了 更新这个数据库文件:一天更新一次,或者使用updatedb更新这个数据库 模糊搜索:文件路径中带有要查找的字符串,就全搜出来了,搜索的文件全路径 大小写敏感 -i 用于忽略大小写 -n 指定列出前几行 locate -n3 profile -r 使用正则表达式 locate -n3 -r "\.conf$"(查找包含conf结尾的前三个文件) find:通过实时查找 实时查找工具,会搜索整个磁盘查找文件 语法: find [option]...[查找路径][查找条件][处理动作] 查找路径:指定具体目标路径;默认为当前目录 查找条件:可以根据文件名,大小,类型,权限等标准进行查找,默认找出指定路径下的所有文件 处理动作:对符合条件的文件做操作,默认输出到屏幕 options: 指搜索层级,find命令默认搜索递归搜索,每个目录都会进入 -maxdepth level 最大搜索目录的深度,指定目录为第1级,也包括比最大级小的目录 -mindepth level 最小搜索目录的深度

Postgres: extract text up to the Nth Character in a String

杀马特。学长 韩版系。学妹 提交于 2021-01-01 04:14:51
问题 How can I extract the text up to the 4th instance of a character in a column? I'm selecting text out of a column called filter_type up to the fourth > character. To accomplish this, I've been trying to find the position of the fourth > character, but it's not working: select substring(filter_type from 1 for position('>' in filter_type)) 回答1: You can use the pattern matching function in Postgres. First figure out a pattern to capture everything up to the fourth > character. To start your

Swapping a character for another in Regex/Javascript

旧街凉风 提交于 2021-01-01 04:05:02
问题 I'm looking to do something like: var a = "This is an A B pattern: ABABA"; a.replace("A", "B"); a.replace("B", "A"); and have it return: => "This is an B A pattern: BABAB" instead of: => "This is an A A pattern: AAAAA" My first thought is to do something like: a.replace("A", "improbablePattern"); a.replace("B", "A"); a.replace("improbablePattern", "B"); How should I really be doing it? 回答1: You could pass a function to your .replace() call with the regex that matches both, like this: var a =

Swapping a character for another in Regex/Javascript

烈酒焚心 提交于 2021-01-01 04:02:24
问题 I'm looking to do something like: var a = "This is an A B pattern: ABABA"; a.replace("A", "B"); a.replace("B", "A"); and have it return: => "This is an B A pattern: BABAB" instead of: => "This is an A A pattern: AAAAA" My first thought is to do something like: a.replace("A", "improbablePattern"); a.replace("B", "A"); a.replace("improbablePattern", "B"); How should I really be doing it? 回答1: You could pass a function to your .replace() call with the regex that matches both, like this: var a =

Swapping a character for another in Regex/Javascript

北战南征 提交于 2021-01-01 04:02:17
问题 I'm looking to do something like: var a = "This is an A B pattern: ABABA"; a.replace("A", "B"); a.replace("B", "A"); and have it return: => "This is an B A pattern: BABAB" instead of: => "This is an A A pattern: AAAAA" My first thought is to do something like: a.replace("A", "improbablePattern"); a.replace("B", "A"); a.replace("improbablePattern", "B"); How should I really be doing it? 回答1: You could pass a function to your .replace() call with the regex that matches both, like this: var a =

Swapping a character for another in Regex/Javascript

安稳与你 提交于 2021-01-01 04:01:34
问题 I'm looking to do something like: var a = "This is an A B pattern: ABABA"; a.replace("A", "B"); a.replace("B", "A"); and have it return: => "This is an B A pattern: BABAB" instead of: => "This is an A A pattern: AAAAA" My first thought is to do something like: a.replace("A", "improbablePattern"); a.replace("B", "A"); a.replace("improbablePattern", "B"); How should I really be doing it? 回答1: You could pass a function to your .replace() call with the regex that matches both, like this: var a =

get specific character

笑着哭i 提交于 2021-01-01 03:56:34
问题 I would like to remove Zero from a string, below is an example : String a : 020200218-0PSS-0010 a.replaceall("-(?:.(?!-))+$", "**REPLACEMENT**") Actual : 020200218-0PSS-0010 Expected : 020200218-0PSS-10 I'm using this regex to catch -0010 : -(?:.(?!-))+$ I just dont know what to do in the REPLACEMENT section to actually remove the unused zero (not the last zero for exemple "10" and not "1") Thanks for reading! 回答1: You could use something like: (?<=-)0+(?=[1-9]\d*$) It translates to "find all