regex-negation

Regex that doesn't match spec.ts and spec.tsx but should match any other .ts and .tsx

夙愿已清 提交于 2020-07-20 05:43:38
问题 I wrote this regex that matches any .ts or .tsx file names but shouldn't match spec.tsx or spec.ts. Below is the regex I wrote. (?!spec)\.(ts|tsx)$ But it fails to ignore.spec.tsx and spec.ts files. What am I doing wrong here? Please advice. 回答1: The negative lookahead syntax ( (?!...) ) looks ahead from wherever it is in the regex. So your (?!spec) is being compared to what follows that point, just before the \. . In other words, it's being compared to the file extension, .ts or .tsx . The

How to match nothing [duplicate]

久未见 提交于 2020-06-29 03:37:29
问题 This question already has answers here : What is a regex to match ONLY an empty string? (9 answers) Closed 11 days ago . This may be a simple question to some: how do you actually match nothing using regex in R? Suppose you have a vector of strings such as this: q <- c("a", "12", "0", "", "300") And suppose further you want to match the empty string "" , how to go about this? It seems one can reasonably well match "" using grep to match the metacharacter . meaning 'any character', either as

How to match nothing [duplicate]

与世无争的帅哥 提交于 2020-06-29 03:37:06
问题 This question already has answers here : What is a regex to match ONLY an empty string? (9 answers) Closed 11 days ago . This may be a simple question to some: how do you actually match nothing using regex in R? Suppose you have a vector of strings such as this: q <- c("a", "12", "0", "", "300") And suppose further you want to match the empty string "" , how to go about this? It seems one can reasonably well match "" using grep to match the metacharacter . meaning 'any character', either as

How to make a regex for files ending in .php?

两盒软妹~` 提交于 2020-04-05 06:20:54
问题 I'm trying to write a very simple regular expression that matches any file name that doesn't end in .php. I came up with the following... (.*?)(?!\.php)$ ...however this matches all filenames. If someone could point me in the right direction I'd be very grateful. 回答1: Almost: .*(?!\.php)....$ The last four dots make sure that there is something to look ahead at , when the look-ahead is checked. The outer parentheses are unnecessary since you are interested in the entire match. The reluctant .

How to make a regex for files ending in .php?

落花浮王杯 提交于 2020-04-05 06:20:22
问题 I'm trying to write a very simple regular expression that matches any file name that doesn't end in .php. I came up with the following... (.*?)(?!\.php)$ ...however this matches all filenames. If someone could point me in the right direction I'd be very grateful. 回答1: Almost: .*(?!\.php)....$ The last four dots make sure that there is something to look ahead at , when the look-ahead is checked. The outer parentheses are unnecessary since you are interested in the entire match. The reluctant .

Regexp in Grok sometimes catches a value sometimes not

一笑奈何 提交于 2020-03-27 05:44:17
问题 I've a code in grok, which captures messages, and if they meet a given criteria, they get a tag. My problem is, that sometimes this filter works while testing, and sometimes does not. The regexp in question is the following: ^(?!(?:\d\d\d\d-\d\d-\d\d.\d\d:\d\d:\d\d)).*$ This line checks if the given message does not begin with a given time stamp format. In other words: if the given message does not begin with this time stamp, then it gets a tag. You can test it yourself with this online

Regexp in Grok sometimes catches a value sometimes not

﹥>﹥吖頭↗ 提交于 2020-03-27 05:43:10
问题 I've a code in grok, which captures messages, and if they meet a given criteria, they get a tag. My problem is, that sometimes this filter works while testing, and sometimes does not. The regexp in question is the following: ^(?!(?:\d\d\d\d-\d\d-\d\d.\d\d:\d\d:\d\d)).*$ This line checks if the given message does not begin with a given time stamp format. In other words: if the given message does not begin with this time stamp, then it gets a tag. You can test it yourself with this online

Regexp in Grok sometimes catches a value sometimes not

試著忘記壹切 提交于 2020-03-27 05:43:09
问题 I've a code in grok, which captures messages, and if they meet a given criteria, they get a tag. My problem is, that sometimes this filter works while testing, and sometimes does not. The regexp in question is the following: ^(?!(?:\d\d\d\d-\d\d-\d\d.\d\d:\d\d:\d\d)).*$ This line checks if the given message does not begin with a given time stamp format. In other words: if the given message does not begin with this time stamp, then it gets a tag. You can test it yourself with this online

matching two or more characters that are not the same

只谈情不闲聊 提交于 2020-03-22 09:03:32
问题 Is it possible to write a regex pattern to match abc where each letter is not literal but means that text like xyz (but not xxy ) would be matched? I am able to get as far as (.)(?!\1) to match a in ab but then I am stumped. After getting the answer below, I was able to write a routine to generate this pattern. Using raw re patterns is much faster than converting both the pattern and a text to canonical form and then comaring them. def pat2re(p, know=None, wild=None): """return a compiled re