regex-negation

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

Ignoring case for a whole pattern of strings

霸气de小男生 提交于 2019-12-12 00:33:12
问题 regexp are not my strong point but I have a list of 4 strings that I want to check for. I created a pattern which is readable(to me) so more can be added easily but I am 99% sure none will be. The list is, and I want to match the string regardless of what case is used. packstation - ( packstation | Packstation | PACKSTATION ) pack station - ( pack station | Pack station | pack Station | Pack Station | PACK STATION ) paketstation - ( paketstation | Paketstation | PAKETSTATION ) paket station -

Why doesn't my function correctly replace when using some regex pattern

て烟熏妆下的殇ゞ 提交于 2019-12-11 17:46:24
问题 This is an extension of this SO question I made a function to see if i can correctly format any number. The answers below work on tools like https://regex101.com and https://regexr.com/, but not within my function(tried in node and browser): const const format = (num, regex) => String(num).replace(regex, '$1') Basically given any whole number, it should not exceed 15 significant digits. Given any decimal, it should not exceed 2 decimal points. so... Now format(0.12345678901234567890, /^\d{1

Match image tag not nested in an anchor tag using regular expression

最后都变了- 提交于 2019-12-11 17:44:21
问题 How would I match images that is not nested inside an anchor tag using regular expression? Here is what I want: No match: <a href="index.html"><img src="images/default.jpg" /></a> Match: <div><img src="images/default.jpg" /></div> Match: <img src="images/default.jpg" /> I'm no good at regex but this is what I came up so far, which doesn't work: [^<a[^>]*>]<img.*?/>[^</a>] I couldn't use lookarounds since PHP wants it to be specific. 回答1: Much of the reason behind your difficulty is simply

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]+@.*(?=[>\]]))

negate the whole regex pattern when negative lookaround doesn't work

為{幸葍}努か 提交于 2019-12-11 13:22:38
问题 I had a regex that matches a P.O. BOX on a given address - /p\.? *o\.? *box/i . But recently my requirement changes to NOT match the P.O. BOX. In other words, the address is valid when P.O. BOX is not found. I was trying to negate that pattern so it matches an address that has no P.O. BOX by using negative lookahead , this is what I came up with so far: /.*(?!p\.? *o\.? *box).*/i , but it is not working right now: https://regex101.com/r/oN1jZ8/1 For example, I try to match the following: this

Regex in C# that contains “this” but not "that

和自甴很熟 提交于 2019-12-11 12:49:51
问题 I need to filter a list of files. Some of these are csv files, and of those, some of them are appended with a control tag, ".cntl". Example: file1.csv, file1.csv.cntl I would like to set up a regex that checks to see if a file contains "csv" and NOT "cntl". Right now I've got this. csv(?!cntl) This is not working. What would a proper regex be? PS. This is all done in C#. 回答1: Your regex should check to see if a file ends with .csv \.csv$ Remember that csv could be contained elsewhere in the

Selectively replace (") doublequotes in a std::string in C++

我与影子孤独终老i 提交于 2019-12-11 09:25:36
问题 I want to selectively replace the (") doublequotes in a C++ std::string. i.e. i want to replace all occurences of (") doublequotes in a string except the 1st and last occurence of (") doublequotes in the string. Example- following code replaces ALL occurence of (") doublequotes std::string str = "\"Hello people \" how are you doing \" what are \" you upto \""; str = std::regex_replace(str, std::regex("\\\""), """); However, i don't want to replace the 1st and last occurenece of the string. i

How to find everything that is not matching a regular expression

早过忘川 提交于 2019-12-11 05:24:33
问题 I would like to search all over thousands of HTML code for bad practice of height, width or any other CSS. for instance I would like to get all places where height is not provided with units, for instance height:40 should be found, but height:40px shouldn't. For that I am using the search program agent ransack, in which I can put regular expression to search within files. Currently my regular expression is: (height:)[\s]*[0-9]*\.?[0-9]+(px) this finds everything that is like height:40px .

How to negative match regex in JavaScript string replace? [duplicate]

帅比萌擦擦* 提交于 2019-12-11 03:15:04
问题 This question already has answers here : Strip all non-numeric characters from string in JavaScript (7 answers) Closed 5 years ago . I am trying to replace with a blank all characters except numbers, but this doesn't works: s.replace(/(?!\d)/g, '') Thanks! 回答1: Use negative character classes: s.replace(/[^0-9]+/g, '') or s.replace(/[^\d]+/g, '') or s.replace(/\D+/g, '') 来源: https://stackoverflow.com/questions/24419609/how-to-negative-match-regex-in-javascript-string-replace