negative-lookahead

.NET Regex Negative Lookahead - what am I doing wrong?

為{幸葍}努か 提交于 2019-12-02 12:21:59
Assuming I have: StartTest NoInclude EndTest StartTest Include EndTest and am using: /StartTest(?!NoInclude)[\s\S]*?EndTest/g Why am I matching both groups? Regexr example: http://regexr.com/3db8m You fail the match with the lookahead if NoInclude appears straight after StartTest . You need a tempered greedy token : (?s)StartTest(?:(?!(?:Start|End)Test|NoInclude).)*EndTest ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ See the regex demo The regex is matching StartTest , then matches any text that is not StartTest , EndTest or NoInclude , up to the EndTest . Since the * is greedy, it will make the .

Regex lookahead only removing the last character

拥有回忆 提交于 2019-12-02 02:49:21
问题 Im creating a regex that searches for a text, but only if there isnt a dash after the match. Im using lookahead for this: Regex: Text[\s\.][0-9]*(?!-) Expected result Result --------------- ------- Text 11 Text 11 Text 11 Text 52- <No Match> Text 5 Test case: https://regex101.com/r/doklxc/1/ The lookahead only seems to be matching with the previous character, which leaves me with Text 5 , while I need it to not return a match at all. Im checking the https://www.regular-expressions.info/

Regex lookahead only removing the last character

感情迁移 提交于 2019-12-02 01:14:19
Im creating a regex that searches for a text, but only if there isnt a dash after the match. Im using lookahead for this: Regex: Text[\s\.][0-9]*(?!-) Expected result Result --------------- ------- Text 11 Text 11 Text 11 Text 52- <No Match> Text 5 Test case: https://regex101.com/r/doklxc/1/ The lookahead only seems to be matching with the previous character, which leaves me with Text 5 , while I need it to not return a match at all. Im checking the https://www.regular-expressions.info/ guides and tried using groups, but I cant wrap my head around this one. How can I make it so the lookbehind

Use Regex to find a phone number on a page not in an anchor

假如想象 提交于 2019-12-01 09:05:52
问题 I have this regex expression that searches for a phone number pattern: [(]?\d{3}[)]?[(\s)?.-]\d{3}[\s.-]\d{4} This matches phone numbers in this format: 123 456 7890 (123)456 7890 (123) 456 7890 (123)456-7890 (123) 456-7890 123.456.7890 123-456-7890 I want to scan an entire page (with JavaScript) looking for this match, but excluding this match that already exists inside an anchor. After the match is found, I want to convert the phone number into a click to call link for mobile devices: (123)

negative lookahead regex on elasticsearch

元气小坏坏 提交于 2019-12-01 06:21:44
I'm trying to do a negative lookahead on an elasticsearch query, the regex is: (?!.*charge)(?!.*encode)(?!.*relate).*night.* the text that I'm matching against is: credited back on night stay, still having issues with construction. causing health issues due to a chemical being sprayed and causes eyes to irritated. I didn't get any lucky. Can someone give a hand? ES query: "query": { "filtered": { "query": { "bool": { "must_not": [ { "regexp": { "message": { "value": "(?!.*charge)(?!.*encode)(?!.*relate).*night.*", "flags_value": 65535 } } } ] } }, "filter": { "match": { "resNb": { "query":

negative lookahead regex on elasticsearch

给你一囗甜甜゛ 提交于 2019-12-01 04:38:32
问题 I'm trying to do a negative lookahead on an elasticsearch query, the regex is: (?!.*charge)(?!.*encode)(?!.*relate).*night.* the text that I'm matching against is: credited back on night stay, still having issues with construction. causing health issues due to a chemical being sprayed and causes eyes to irritated. I didn't get any lucky. Can someone give a hand? ES query: "query": { "filtered": { "query": { "bool": { "must_not": [ { "regexp": { "message": { "value": "(?!.*charge)(?!.*encode)(

Variable-Width Lookbehind Issue in Python

隐身守侯 提交于 2019-11-30 18:55:47
I got the following scenarios: 1) car on the right shoulder 2) car on the left shoulder 3) car on the shoulder I want to match "shoulder" when left|right is not present. So only 3) return "shoulder" re.compile(r'(?<!right|right\s*)shoulder') sre_constants.error: look-behind requires fixed-width pattern It seems like I can't use \s* and "|" How can I solve this. Thanks in advance! zx81 regex module: variable-width lookbehind In addition to the answer by HamZa , for any regex of any complexity in Python, I recommend using the outstanding regex module by Matthew Barnett . It supports infinite

RegEx - Exclude Matched Patterns

左心房为你撑大大i 提交于 2019-11-30 08:28:14
I have the below patterns to be excluded. make it cheaper make it cheapere makeitcheaper.com.au makeitcheaper making it cheaper www.make it cheaper ww.make it cheaper.com I've created a regex to match any of these. However, I want to get everything else other than these. I am not sure how to inverse this regex I've created. mak(e|ing) ?it ?cheaper Above pattern matches all the strings listed. Now I want it to match everything else. How do I do it? From the search, it seems I need something like negative lookahead / look back. But, I don't really get it. Can some one point me in the right

Use Regex to find a phone number on a page not in an anchor

我与影子孤独终老i 提交于 2019-11-29 11:59:38
I have this regex expression that searches for a phone number pattern: [(]?\d{3}[)]?[(\s)?.-]\d{3}[\s.-]\d{4} This matches phone numbers in this format: 123 456 7890 (123)456 7890 (123) 456 7890 (123)456-7890 (123) 456-7890 123.456.7890 123-456-7890 I want to scan an entire page (with JavaScript) looking for this match, but excluding this match that already exists inside an anchor. After the match is found, I want to convert the phone number into a click to call link for mobile devices: (123) 456-7890 --> <a href="tel:1234567890">(123) 456-7890</a> I'm pretty sure I need to do a negative

RegEx - Exclude Matched Patterns

白昼怎懂夜的黑 提交于 2019-11-29 11:42:34
问题 I have the below patterns to be excluded. make it cheaper make it cheapere makeitcheaper.com.au makeitcheaper making it cheaper www.make it cheaper ww.make it cheaper.com I've created a regex to match any of these. However, I want to get everything else other than these. I am not sure how to inverse this regex I've created. mak(e|ing) ?it ?cheaper Above pattern matches all the strings listed. Now I want it to match everything else. How do I do it? From the search, it seems I need something