lookbehind

Variable-Width Lookbehind Issue in Python

点点圈 提交于 2020-01-11 01:26:28
问题 I got the following scenarios: 1) car on the right shoulder 2) car on the left shoulder 3) car on the shoulder I want to match "shoulder" when left|right is not present. So only 3) return "shoulder" re.compile(r'(?<!right|right\s*)shoulder') sre_constants.error: look-behind requires fixed-width pattern It seems like I can't use \s* and "|" How can I solve this. Thanks in advance! 回答1: regex module: variable-width lookbehind In addition to the answer by HamZa, for any regex of any complexity

Quantifier range not working in lookbehind

牧云@^-^@ 提交于 2020-01-02 05:05:29
问题 Okay so I'm working on a project where I need a regex that can match a * followed by 1-4 spaces or tabs and then followed by a row of text. Right now I'm using .* after the lookbehind for testing purposes. However I can get it to match explicitly 1, 2, or 4 spaces/tabs but not 1-4. I'm testing against the following block * test line here * Second test * Third test * Another test And these are the two patterns I'm testing (?<=(\*[ \t]{3})).* which works just as expected and matches the 2nd

Regex matching left single quotation outside the double quotations

旧街凉风 提交于 2019-12-31 07:41:57
问题 Note : left double quotation (") = &ldquo right double quotation (") = &rdquo left single quotation (') = &lsquo My current regex is this (?<!.*&ldquo.*)&lsquo It matches the &lsquo in here (which is right): &ldquoThis is a sample&rdquo &lsquosample text It also matches the &lsquo in here (which I don't want to happen because the single quote is inside the left and right double quote): &ldquoThis &lsquois a sample&rdquo How can I write a regex that will match every &lsquo that are NOT inside

Issue with a Look-behind Regular expression (Ruby)

放肆的年华 提交于 2019-12-29 08:31:47
问题 I wrote this regex to match all href and src links in an HTML page; (I know I should be using a parser; this just experimenting): /((href|src)\=\").*?\"/ # Without look-behind It works fine, but when I try to modify the first portion of the expression as a look-behind pattern: /(?<=(href|src)\=\").*?\"/ # With look-behind It throws an error stating 'invalid look-behind pattern'. Any ideas, whats going wrong with the look-behind? 回答1: Lookbehind has restrictions: (?<=subexp) look-behind (?<

Issue with a Look-behind Regular expression (Ruby)

人盡茶涼 提交于 2019-12-29 08:31:09
问题 I wrote this regex to match all href and src links in an HTML page; (I know I should be using a parser; this just experimenting): /((href|src)\=\").*?\"/ # Without look-behind It works fine, but when I try to modify the first portion of the expression as a look-behind pattern: /(?<=(href|src)\=\").*?\"/ # With look-behind It throws an error stating 'invalid look-behind pattern'. Any ideas, whats going wrong with the look-behind? 回答1: Lookbehind has restrictions: (?<=subexp) look-behind (?<

Negative lookbehind in R with multi-word separation

夙愿已清 提交于 2019-12-25 16:23:47
问题 I'm using R to do some string processing, and would like to identify the strings that have a certain word root that are not preceded by another word of a certain word root. Here is a simple toy example. Say I would like to identify the strings that have the word "cat/s" not preceded by "dog/s" anywhere in the string. tests = c( "dog cat", "dogs and cats", "dog and cat", "dog and fluffy cats", "cats and dogs", "cat and dog", "fluffy cats and fluffy dogs") Using this pattern, I can pull the

RegExp in ActionScript 3: How to exclude a complex prefix?

£可爱£侵袭症+ 提交于 2019-12-25 04:16:13
问题 AS3 RegExp engine (and ECMAScript based JavaScript) do not support complex "lookbehind" expressions. (lookahead expressions are fully supported.) For example: (?<=<body>)(.*?)(?=<\/body>) will work but; (?<=<body\b[^>]*>)(.*?)(?=<\/body>) will not work in AS3. What I need is to match a complex prefix but exclude it in the final match. In the example above; I'm trying to get the body contents in an HTML text but NOT the opening and closing body tags. And the actual test text looks like this:

Regular Expression - Match all but first letter in each word in sentence

非 Y 不嫁゛ 提交于 2019-12-21 20:03:36
问题 I've almost got the answer here, but I'm missing something and I hope someone here can help me out. I need a regular expression that will match all but the first letter in each word in a sentence. Then I need to replace the matched letters with the correct number of asterisks. For example, if I have the following sentence: There is an enormous apple tree in my backyard. I need to get this result: T**** i* a* e******* a**** t*** i* m* b*******. I have managed to come up with an expression that

Notepad++ Regex Find/Replace Using Look Behind not Working

允我心安 提交于 2019-12-20 04:59:36
问题 I have the following CSS markup. .previous-container{ float:left; } .primary-commands { float:right; } Using the regex syntax search (?<=[\s,;])([a-zA-Z\-]+): it highlights the CSS property name as expected, however, upon clicking replace nothing is replaced. I have tried using group token syntax in replace line e.g. $[nth group] and any plain literal string replacement. No matter my attempts it will not replace the matched string with anything. I am using notepad++ version 6.7.5. Perhaps

Get more than 1 quotations in text paragraph in R regex

℡╲_俬逩灬. 提交于 2019-12-20 04:15:49
问题 First: Find the texts that are inside the quotations "I want everything inside here". Second: To extract 1 sentence before quotation. I would like to achieve this output desirable by look behind regex in R if possible Example: Yoyo. He is sad. Oh no! "Don't sad!" Yeah: "Testing... testings," Boys. Sun. Tree... 0.2% green,"LL" "WADD" HOLA. Desired Output: [1] Oh no! "Don't sad!" [2] Yeah: "Testing... testings" [3] Tree... 0.2% green, "LL" [4] Tree... 0.2% green, "LL" "WADD" dput: "Yoyo. He is