regex-negation

Regular expression to match strings that do NOT contain all specified elements

浪尽此生 提交于 2021-02-05 06:30:51
问题 I'd like to find a regular expression that matches strings that do NOT contain all the specified elements, independently of their order. For example, given the following data: one two three four one three two one two one three four Passing the words two three to the regex should match the lines one two , one three and four . I know how to implement an expression that matches lines that do not contain ANY of the words, matching only line four : ^((?!two|three).)*$ But for the case I'm

How to replace everything but a specified string using regex

ぃ、小莉子 提交于 2021-02-04 17:46:18
问题 I've been looking through and out of stackoverflow for this, but I haven't had any luck. The string I want to work with is "xbananay", where 'x' and 'y' can be any random combination of letters or numbers with any length. So my string could simply be "qrstbananag", but it could also be "abcbanana12345" for example. I want to use, and only use , javascript's replace function to replace everything BUT "banana". I already have some regex that can find banana, but the replace function, as

Regex: Match everything in text paragraph except specific phrases

烂漫一生 提交于 2021-01-27 20:05:02
问题 I'm writing a free plugin for Google Docs and processing paragraphs of text. I need a regular expression to match everything except a phrase (i.e. multiple words separated with spaces). For example, when searching the text The quick brown fox jumped over the lazy dog I want to match everything except quick brown and lazy with the expected result being The fox jumped over the dog . \b((?!(lazy)\b).)+ This works; it matches all text except lazy and I get The quick brown fox jumped over the dog

Regex to match number with different digits and minimum length

*爱你&永不变心* 提交于 2021-01-27 14:24:11
问题 I am trying to write a regex (to validate a property on a c# .NET Core model, which generates javascript expression) to match all numbers composed by at least two different digits and a minimum length of 6 digits. For example: 222222 - not valid 122222 - valid 1111125 - valid I was trying the following expression: (\d)+((?!\1)(\d)) , which matches the sequence if has different digits but how can I constrain the size of the whole pattern to {6,} ? Many thanks 回答1: You may use ^(?=\d{6})(\d)\1*

Regex match everything except words between quotes

心已入冬 提交于 2020-12-31 05:12:21
问题 I want to write a regex what matches everything except words between quotes. Ex.: Lorem ipsum "dolor" sit amet, consectetur "adipiscing" elit. Nunc ultrices varius odio, "ut accumsan nisi" aliquet vitae. "Ut faucibus augue tortor, at aliquam purus dignissim eget." So I want a regex what matches the following strings: Lorem ipsum sit amet, consectetur elit. Nunc ultrices varius odio, aliquet vitae. I only have the following expression that matches substrings inside quotes: ([\"'])(?:\\\1|.)*?

Regex match everything except words between quotes

谁说我不能喝 提交于 2020-12-31 05:09:57
问题 I want to write a regex what matches everything except words between quotes. Ex.: Lorem ipsum "dolor" sit amet, consectetur "adipiscing" elit. Nunc ultrices varius odio, "ut accumsan nisi" aliquet vitae. "Ut faucibus augue tortor, at aliquam purus dignissim eget." So I want a regex what matches the following strings: Lorem ipsum sit amet, consectetur elit. Nunc ultrices varius odio, aliquet vitae. I only have the following expression that matches substrings inside quotes: ([\"'])(?:\\\1|.)*?

Regex match everything except words between quotes

試著忘記壹切 提交于 2020-12-31 05:09:56
问题 I want to write a regex what matches everything except words between quotes. Ex.: Lorem ipsum "dolor" sit amet, consectetur "adipiscing" elit. Nunc ultrices varius odio, "ut accumsan nisi" aliquet vitae. "Ut faucibus augue tortor, at aliquam purus dignissim eget." So I want a regex what matches the following strings: Lorem ipsum sit amet, consectetur elit. Nunc ultrices varius odio, aliquet vitae. I only have the following expression that matches substrings inside quotes: ([\"'])(?:\\\1|.)*?

Is [\s\S] same as . (dot)?

别等时光非礼了梦想. 提交于 2020-12-13 09:36:20
问题 When we include shorthand for character class and negated-character class in same character class, is it same as dot . which mean any character ? I did a test on regex101.com and every character matched. Is [\s\S] [\w\W] and [\d\D] same as . ? I want to know if this behavior is persistent in web's front and backend languages like Javascript, Php, Python and others. 回答1: "No" it is not the same. It has an important difference if you are not using the single line flag (meaning that . does not

Is [\s\S] same as . (dot)?

爱⌒轻易说出口 提交于 2020-12-13 09:36:06
问题 When we include shorthand for character class and negated-character class in same character class, is it same as dot . which mean any character ? I did a test on regex101.com and every character matched. Is [\s\S] [\w\W] and [\d\D] same as . ? I want to know if this behavior is persistent in web's front and backend languages like Javascript, Php, Python and others. 回答1: "No" it is not the same. It has an important difference if you are not using the single line flag (meaning that . does not