lookbehind

Regex pattern that does not match certain extensions?

徘徊边缘 提交于 2019-12-03 20:52:09
问题 I have this pattern written ^.*\.(?!jpg$|png$).+$ However there is a problem - this pattern matches file.name.jpg (2 dots) It works correctly (does not match) on filename.jpg. I am trying to figure out how to make it not match ANY .jpg files even if the file's name has 2 or more dots in it. I tried using a look behind but python complains about not using a fixed width (which I'm not exactly sure what that means, but the file name will be variable length.) 回答1: This should work: ^.*\.(?!jpg$

Is there a bug in Ruby lookbehind assertions (1.9/2.0)?

霸气de小男生 提交于 2019-12-03 19:46:08
问题 Why doesn't the regex (?<=fo).* match foo (whereas (?<=f).* does)? "foo" =~ /(?<=f).*/m => 1 "foo" =~ /(?<=fo).*/m => nil This only seems to happen with singleline mode turned on (dot matches newline); without it, everything is OK: "foo" =~ /(?<=f).*/ => 1 "foo" =~ /(?<=fo).*/ => 2 Tested on Ruby 1.9.3 and 2.0.0. See it on Rubular EDIT: Some more observations: Adding an end-of-line anchor doesn't change anything: "foo" =~ /(?<=fo).*$/m => nil But together with a lazy quantifier, it "works":

How to non-greedy multiple lookbehind matches

我只是一个虾纸丫 提交于 2019-12-03 18:00:25
问题 Source: <prefix><content1><suffix1><prefix><content2><suffix2> Engine: PCRE RegEx1: (?<=<prefix>)(.*)(?=<suffix1>) RegEx2: (?<=<prefix>)(.*)(?=<suffix2>) Result1: <content1> Result2: <content1><suffix1><prefix><content2> The desired result for RegEx2 is just <content2> but it is obviously greedy. How do I make RegEx2 non-greedy and use only the last matching lookbehind? [I hope I have translated this correctly from the NoteTab syntax. I don't do much RegEx coding. The <prefix>, <content> &

Can you salvage my negative lookbehind example for commifying numbers?

試著忘記壹切 提交于 2019-12-03 08:48:02
问题 In the "Advanced Regular Expresssion" chapter in Mastering Perl, I have a broken example for which I can't figure out a nice fix. The example is perhaps trying to be too clever for its own good, but maybe someone can fix it for me. There could be a free copy of the book in it for working fixes. :) In the section talking about lookarounds, I wanted to use a negative lookbehind to implement a commifying routine for numbers with fractional portions. The point was to use a negative lookbehind

Can you salvage my negative lookbehind example for commifying numbers?

本秂侑毒 提交于 2019-12-03 00:22:34
In the "Advanced Regular Expresssion" chapter in Mastering Perl , I have a broken example for which I can't figure out a nice fix. The example is perhaps trying to be too clever for its own good, but maybe someone can fix it for me. There could be a free copy of the book in it for working fixes. :) In the section talking about lookarounds, I wanted to use a negative lookbehind to implement a commifying routine for numbers with fractional portions. The point was to use a negative lookbehind because that was the topic. I stupidly did this: $_ = '$1234.5678'; s/(?<!\.\d)(?<=\d)(?=(?:\d\d\d)+\b)/,

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

爱⌒轻易说出口 提交于 2019-12-02 04:43:11
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 there is something obvious I am missing here? Based on comments to the original question here are some

Invalid regular expression error

三世轮回 提交于 2019-12-01 19:59:21
I'm trying to retrieve the category part this string " property_id=516&category=featured-properties ", so the result should be "featured-properties", and I came up with a regular expression and tested it on this website http://gskinner.com/RegExr/ , and it worked as expected, but when I added the regular expression to my javascript code, I had a "Invalid regular expression" error, can anyone tell me what is messing up this code? Thanks! var url = "property_id=516&category=featured-properties" var urlRE = url.match('(?<=(category=))[a-z-]+'); alert(urlRE[0]); ajm Positive lookbehinds (your ?<=

Regex negative lookbehind in Ruby doesn't seem to work

折月煮酒 提交于 2019-12-01 16:42:37
问题 Making an argument parser. I want to split a string into an array where the delimiter is ", " except when preceded by "|" . That means string "foo, ba|, r, arg" should result in `["foo", "ba|, r", "arg"]` I'm trying to use this regex: (?<!\|), which works in http://regexhero.net/tester/ but when I try args.split(/(?<!\|), /) in ruby, I get an error: undefined (?...) sequence: /(?<!\|), / 回答1: Ruby's regex engine doesn't support lookbehind (yet). You'd need to switch to 1.9 or use Oniguruma.

Regular expression: matching words between white space

一笑奈何 提交于 2019-12-01 05:10:01
Im trying to do something fairly simple with regular expression in python... thats what i thought at least. What i want to do is matching words from a string if its preceded and followed by a whitespace. If its at the beginning of the string there is no whitespace required before - if its at the end, dont't search for whitespace either. Example: "WordA WordB WordC-WordD WordE" I want to match WordA WordB WordE . I only came up with overcomplicated way of doing this... (?<=(?<=^)|(?<=\s))\w+(?=(?=\s)|(?=$)) It seems to me there has to be a simple way for such a simple problem.... I figured i

Regex pattern that does not match certain extensions?

只愿长相守 提交于 2019-11-30 19:23:29
I have this pattern written ^.*\.(?!jpg$|png$).+$ However there is a problem - this pattern matches file.name.jpg (2 dots) It works correctly (does not match) on filename.jpg. I am trying to figure out how to make it not match ANY .jpg files even if the file's name has 2 or more dots in it. I tried using a look behind but python complains about not using a fixed width (which I'm not exactly sure what that means, but the file name will be variable length.) This should work: ^.*\.(?!jpg$|png$)[^.]+$ Use os.path 's nifty functions to properly split up the filepath into components for easier