regex-negation

XML Schema (XSD) 1.0 xs:pattern regex to match 4 digits as a string?

笑着哭i 提交于 2019-12-06 15:06:25
问题 How can I match a specific sequence of digits as if it were a string in an XML Schema xs:pattern ? Say I have some tags containing arbitrary 10-character strings like <string>12345678990</string> And I want to rule out all tags with a specific blacklist of arbitrary sequences like 1234 , 2435 , ``9587`, or some such. How do I address the specific 4-digit sub-string in order to negate it and add it to a list of xs:pattern restrictions for <string> 's content model? 回答1: I don't think there is

Regex that says what NOT to match?

让人想犯罪 __ 提交于 2019-12-06 14:05:29
I’m wondering how to match any characters except for a particular string (call it "for" ) in a regex. I was thinking maybe it was something like this: [^for]* — except that that doesn’t work. I’m sure this a dup. One way is to start your pattern with a lookahead like this: (?=\A(?s:(?!for).)*\z) That can be written like this in any regex system worth bothering with: (?x) # turn /x mode on for commentary & spacing (?= # lookahead assertion; hence nonconsumptive \A # beginning of string (?s: # begin atomic group for later quantification # enable /s mode so dot can cross lines (?! for ) #

JavaScript regex for blacklisting words [duplicate]

ぐ巨炮叔叔 提交于 2019-12-06 12:26:25
This question already has answers here : Regex: match everything but specific pattern (7 answers) Closed 2 years ago . I'm trying to write a regex to blacklist certain words. I'm able to create a whitelist like /^(carrots|onions|corn)$/ but how would I convert that into a blacklist? Edit: To clarify, I'm matching this blacklist against a whole string. For example "corndog" should be allowed. I want the regex equivalent of blacklistArray.indexOf(word) === -1 Use negative lookahead: ^(?!.*(?:carrots|onions|corn)) 来源: https://stackoverflow.com/questions/43641351/javascript-regex-for-blacklisting

Rewrite regex without negation

不想你离开。 提交于 2019-12-06 11:16:53
I have wrote this regex to help me extract some links from some text files: https?:\/\/(?:.(?!https?:\/\/))+$ Because I am using golang/regexp lib, I'm not able to use it, due to my negation (?!.. What I would like to do with it, is to select all the text from the last occurance of http/https till the end. sometextsometexhttp://websites.com/path/subpath/#query1sometexthttp://websites.com/path/subpath/#query2 => Output: http://websites.com/path/subpath/#query2 Can anyone help me with a solution, I've spent several hours trying different ways of reproducing the same result with no success. Try

Regex match everything but

只谈情不闲聊 提交于 2019-12-06 07:35:56
I would like to create a regular expression to match every word, whitespace, punctuation and special characters in a string except for specific keywords or phrases. Because I only can modify regex, not server code I have to use match instead of replace. I have something like this so far: (?!(quick|brown|fox|the lazy))\b\w+ but it ignores white spaces and special characters in this tool Thanks. Does this work for you (?!(quick|brown|fox|the lazy))(\b\w+|[^\w]) ? Do you have any examples? 来源: https://stackoverflow.com/questions/3732105/regex-match-everything-but

Splitting string into matching and non-matching groups in javascript

别来无恙 提交于 2019-12-06 04:49:23
I am trying to split the string into an array of strings those matching a regular expression and those that don't: string = "Lazy {{some_animal}} jumps over.." # do some magic with regex /({{\s?[\w]+\s?}})/g and its negation array = ["Lazy ", "{{some_animal}}", " jumps over.."] Best performant way to do that in javascript? You can use String match for that The regex below simply matches anything that's not a mustach, optionally surrounded by mustaches. Example snippet: var str = "Lazy {{some_animal}} jumps over.."; const pattern = /\{*[^{}]+\}*/g; var array = str.match(pattern); console.log

Regex Query Help - Lookbehind

一曲冷凌霜 提交于 2019-12-06 02:29:57
This is somewhat related to: Regular Expression - Formatting text in a block - IM but a different problem. Looking for - 's wrapping text with the following conditions: Conditions: token can be at start or end of line token must be surround by space or one or more symbols: {.,!@#$....}. must not be a normal character [a-zA-Z] surrounding the - pair in question. See Sample test 3 ...w-thank you- Test 4 and 5 succeed because the - is wrapped with [^a-zA-Z] token must not be followed by a space on the first - or a space preceding the last - "-Wow -" will not be a match as the closing - was

Using regex to match non-word characters BUT NOT smiley faces

房东的猫 提交于 2019-12-05 20:16:48
I have a Java program which is supposed to remove all non-letter characters from a string, except when they are a smiley face such as =) or =] or :P It's very easy to match the opposite with [a-zA-Z ]|=\)|=\]|:P but I cannot figure out how to negate this expression. Since I am using the String.replaceAll() function it must be in the negated form. I believe part of the issue may come from the fact that smiles are generally 2 characters long, and I am only matching 1 character at a time? Interestingly, replaceAll("(?![Tt])[Oo]","") removes every occurrence of the letter O, even in the word "to."

Regex with exclusion chars and another regex

99封情书 提交于 2019-12-05 20:13:48
How to write regex which find word (without whitespace) that doesn't contain some chars (like * or # ) and sentence also (like level10 or level2 - it should be also regex - level[0-9]+ ). It will be simple for chars excluded ( [^\\s^#^*]+ ) but how to exclude this 'level' example too ? I want to exclude chars AND level with number. Examples: weesdlevel3fv - shouldn't match because of 'level3' we3rlevelw4erw - should match - there is level without number dfs3leveldfvws#3vd - shouldn't match - level is good, but '#' char appeared level4#level levelw4_level - threat as two words because of

Regex match everything between two {}

橙三吉。 提交于 2019-12-05 17:02:20
I was looking at different answers here but unfortunately none of them was good for my case. So I hope you don't mind about it. So I need to match everything between two curly brackets {} except situation when match starts with @ and without these curly brackets e.g: "This is a super text { match_this }" "{ match_this }" "This is another example @{deal_with_it}" Here are my test strings, 1,2,3 are valid while the last one shouldn't be: 1 {eww} 2 r23r23{fetwe} 3 #{d2dded} 4 @{d2dded} I was trying with: (?<=[^@]\{)[^\}]*(?=\}) Then only 2th and 3th options were matches (without the first one)