regex-negation

.NET Regex Negative Lookahead - What am I doing wrong (round 2!) [duplicate]

旧巷老猫 提交于 2019-12-13 10:28:18
问题 This question already has an answer here : .NET Regex Negative Lookahead - what am I doing wrong? (1 answer) Closed 3 years ago . I asked this previously and used what I believe to be entirely too simple of a construct, so I'm trying again... Assuming that I have: This is a random bit of information from 0 to 1. This is a non-random bit of information I do NOT want to match This is the end of this bit This is a random bit of information from 0 to 1. This is a non-random bit of information I

Regex NOT Operation

丶灬走出姿态 提交于 2019-12-13 04:32:47
问题 I have condition where I have to select anything which is not part of span tag. Input - the <span class='ptc-highlightedSearchResult'>PISTON</span> has their <span class='ptc-highlightedSearchResult'>ROD</span> ring regex which selects <span> tag and it's content - (<span[^>]+class\s*=\s*("|')ptc-highlightedSearchResult\2[^>]*>)[^<]*(</span>) I'm able to select whatever comes in span and their content but not otherwise. Any help on NOT operation will be appreciated. 回答1: You can use this: ((?

Regular expression, how to find all A tags which do not contain tag IMG inside it?

余生颓废 提交于 2019-12-13 04:06:17
问题 Let's suppose that we have such HTML code. We need to get all <a href=""></a> tags which DO NOT contain img tag inside it. <a href="http://domain1.com"><span>Here is link</span></a> <a href="http://domain2.com" title="">Hello</a> <a href="http://domain3.com" title=""><img src="" /></a> <a href="http://domain4" title=""> I'm the image <img src="" /> yeah</a> I'm using this regular expression to find all the a tag links: preg_match_all("!<a[^>]+href=\"?'?([^ \"'>]+)\"?'?[^>]*>(.*?)</a>!is",

Regex negative lookahead in c#

我只是一个虾纸丫 提交于 2019-12-12 14:38:08
问题 I need to match ["this" but not :["this" I have this code: Match match = Regex.Match(result, @"\[""(.*?)""", RegexOptions.IgnoreCase); while (match.Success) { MessageBox.Show(match.Groups[1].Value.Trim()); } I have tried the pattern @"(?!:)\[""(.*?)""" , but it still match :["this" . Whats the pattern I need to achieve this? 回答1: You are looking ahead (rightwards in the string) when you want to be looking behind (leftwards in the string). Try @"(?<!:)\[""(.*?)""" instead. 回答2: I used

Replace everything except positive/negative numbers

本小妞迷上赌 提交于 2019-12-12 14:25:07
问题 There are many questions already answered for replacing everything positive numbers. But, I couldn't find any answer which preserves both positive and negative numbers. I want to replace everything that isn't number(positive or negative). The output should be the following eg. 0 | success. id - 1234| -> 0 1234 and -10 | failure. id - 2345| -> -10 2345 Apparently this answers for the positive part. 回答1: You can use this regex to match positive/negative integers: [+-]?\b\d+\b RegEx Demo to

Regex, detect no spaces in the string

巧了我就是萌 提交于 2019-12-12 12:47:58
问题 This is my current regex check: const validPassword = (password) => password.match(/^(?=.*\d)(?=.\S)(?=.*[a-zA-Z]).{6,}$/); I have a check for at least 1 letter and 1 number and at least 6 characters long. However I also want to make sure that there are no spaces anywhere in the string. So far I'm able to enter in 6 character strings with spaces included :( Found this answer here, but for some reason in my code it's passing. What is the regular expression for matching that contains no white

Negative lookahead with capturing groups

人盡茶涼 提交于 2019-12-12 10:45:31
问题 I'm attempting this challenge: https://regex.alf.nu/4 I want to match all strings that don't contain an ABBA pattern. Match: aesthophysiology amphimictical baruria calomorphic Don't Match anallagmatic bassarisk chorioallantois coccomyces abba Firstly, I have a regex to determine the ABBA pattern. (\w)(\w)\2\1 Next I want to match strings that don't contain that pattern: ^((?!(\w)(\w)\2\1).)*$ However this matches everything. If I simplify this by specifying a literal for the negative

Extract all html tag closed with a regex expression

谁都会走 提交于 2019-12-12 04:05:35
问题 I work on R, and I will want to extract all HTML tag closed from a PlainTextDocument. I use a gsub method with a regex : gsub("<?!([^<]/*)>"," ",fm,perl=TRUE,ignore.case=TRUE) But, the slash '/' isn't evaluated. I think I wasn't very clear. Here is what I need to do : I have a text (a HTML document) and I want to only keep the tags ( <> and </> ). I thought using gsub would be a good idea, but maybe you have a better solution. 回答1: The wording of your question is unclear, and your regex doesn

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

Regex match string that ends with number

孤者浪人 提交于 2019-12-12 03:37:15
问题 What is a regex to match a string that ends with a number for example "c1234" - match "c12" - match "c" - no match Tried this but it doesn't work (?|c(?|[0-9]*$)) Thanks again, The beggining string needs to be specific too 回答1: Just use \d$ to check your string ends with a digit If you want your string to be a "c" followed by some digits, use c\d+$ 回答2: To match any string ending with a digit use: [\s\S]*\d$ if (preg_match('/[\s\S]*\d$/', $value)) { #match } else { #no match } 回答3: You can