regex-lookarounds

Regular expressions negative lookahead

孤人 提交于 2019-12-12 08:51:03
问题 I'm doing some regular expression gymnastics. I set myself the task of trying to search for C# code where there is a usage of the as-operator not followed by a null-check within a reasonable amount of space. Now I don't want to parse the C# code. E.g. I want to capture code snippets such as var x1 = x as SimpleRes; var y1 = y as SimpleRes; if(x1.a == y1.a) however, not capture var x1 = x as SimpleRes; var y1 = y as SimpleRes; if(x1 == null) nor for that matter var x1 = x as SimpleRes; var y1

Discover identically adjacent strings with regex and python

匆匆过客 提交于 2019-12-12 03:39:38
问题 Consider this text: ... bedeubedeu France The Provençal name for tripe bee balmbee balm Bergamot beechmastbeechmast Beech nut beech nutbeech nut A small nut from the beech tree, genus Fagus and Nothofagus, similar in flavour to a hazelnut but not commonly used. A flavoursome oil can be extracted from them. Also called beechmast beechwheatbeechwheat Buckwheat beefbeef The meat of the animal known as a cow (female) or bull (male) (NOTE: The Anglo- saxon name ‘Ox’ is still used for some of what

Fixing Negative Assertion for end of string

China☆狼群 提交于 2019-12-12 02:20:06
问题 I am trying to accept a capture group only if the pattern matches and there is not a specific word before the end of the group. I've tried a # of approaches and none seem to work, clearly I'm not getting the concept: https://regex101.com/r/iP2xY0/3 https://regex101.com/r/iP2xY0/4 Regardless of what I do my capture group captures something and my goal is if the reject word exists in the middle of the pattern to return no match. RC:\*.*?(?P<Capture>(Bob|David|Ted|Alice))(?!Reject).* RC:* Hi Bob

Whatsapp chat log parsing with regex

╄→гoц情女王★ 提交于 2019-12-11 19:28:35
问题 I'm trying to parse a whatsapp chat log using regex. I have a solution that works for most cases but I'm looking to improve it but don't know how to since I am quite new to regex. The chat.txt file looks like this: [06.12.16, 16:46:19] Person One: Wow thats amazing [06.12.16, 16:47:13] Person Two: Good morning and this goes over multiple lines as it is a very long message [06.12.16, 16:47:22] Person Two: :: While my solution so far would parse most of these messages correctly, however I have

Return only one group with OR condition in Regex

我怕爱的太早我们不能终老 提交于 2019-12-11 15:17:24
问题 I have to write a Regex to fetch Email Address from a sentence. I want it to be returned with Group 1 only. Regex: \[mailto:(.+)\]|<(.+@.+\..+)> Input String: Hello my Email Address is <foo@hotmail.com> - Return foo@hotmail.com as Group1. Hello my Email Address is [mailto: foo@hotmail.com] - Return foo@hotmail.com as Group2. I want if any of the string matches then it should be returned in Group1. Is there any way to do this? 回答1: You may use regular expression: (?=\S+@)([^<\s]+@.*(?=[>\]]))

Simulate a general positive lookbehind for VBA regex

蹲街弑〆低调 提交于 2019-12-11 14:09:34
问题 There are a plethora of questions about lookbehinds in VBA. The problem is that, while there are positive and negative lookaheads, VBA doesn't support lookbehinds at all. Most of the questions people have asked seek to solve a very specific problem of extracting strings from text and the Stack Overflow community has been very helpful in providing workarounds for these particular cases. My question is, could you write a function in VB that simulates positive lookbehind by accepting Regex

replace characters in notepad++ BUT exclude characters inside single quotation marks(4th)

给你一囗甜甜゛ 提交于 2019-12-11 11:48:07
问题 In replace characters in notepad++ BUT exclude characters inside single quotation marks(2nd) " Jonny 5 " solved this question - BUT - if I have a construct like this: SELECT column_name FROM table_name WHERE column_name IN ('A' , 'st9u' ,'Meyer', ....); WHERE a.object_type IN (' 'TABLE'', ''MATerialIZED VIE3W' ') vpl_text := IS_GOING_SMALL_CORRECT (1) vpl_text := TO_CHAR(vpl_text_old) || ' ' ||...; -- ------ vpl_text := STAYS_UPPER_ERROR (2) vpl_text := TO_CHAR(vpl_text_old) || '' ||...; -- -

Weird negative lookahead handling in hgignore

大兔子大兔子 提交于 2019-12-11 08:24:58
问题 Out of a huge source tree, i want just one subfolder be tracked by Mercurial. specific/component/subfolder In any decent regex tool (Regex Coach, regexpal.com), the following is absolutely sufficient (and understandable) ^(?!specific/component/subfolder).+ meanwhile .hgignore insists on having ^(?!extras).+ ^extras/(?!extensions).+ ^extras/extensions/(?!sharing).+ as soon as i put slash inside the lookahead group, nothing gets through. Before calling this a bug (perhaps of yet another

Add text to string using regular expression(preg_replace:php) with restricted words

两盒软妹~` 提交于 2019-12-11 07:45:45
问题 I have a boolean search string for third party index search service: Germany or (Indian, Tech*) I want my result to be after processing: Germany[45] or (Indian[45], Tech*[45]) . Here 45 is the weight needed by the search service. After googling around for long I was able to get the result: Germany[45] or (Indian[45], Tech[45]*) . Here you can see * has came after [45] which is not required. The output should be: Germany[45] or (Indian[45], Tech*[45]) , look for * before [45] . Code: preg

What is the equivalent to \K for regex in Powershell?

久未见 提交于 2019-12-11 05:56:59
问题 I have created a regular expression on regex101 that works as expected, however the problem is that one part is apparently not valid in Powershell; the \K . Essentially I am looking for instances of a string, and returning the entire word after the instance of the string. So here is an example: \btest\s+\K\S+ This finds every example of the word test and returns the word after it. I did try experimenting with Lookaheads and Lookbehinds, while some of those do work, they are still either