regex-lookarounds

Regex lookahead

坚强是说给别人听的谎言 提交于 2019-12-22 07:01:37
问题 I am using a regex to find: test:? Followed by any character until it hits the next: test:? Now when I run this regex I made: ((?:test:\?)(.*)(?!test:\?)) On this text: test:?foo2=bar2&baz2=foo2test:?foo=bar&baz=footest:?foo2=bar2&baz2=foo2 I expected to get: test:?foo2=bar2&baz2=foo2 test:?foo=bar&baz=foo test:?foo2=bar2&baz2=foo2 But instead it matches everything. Does anyone with more regex experience know where I have gone wrong? I've used regexes for pattern matching before but this is

find search item plus 4 lines before and after

China☆狼群 提交于 2019-12-21 22:29:16
问题 I am using notepad++ and would like to find the context in which a particular string occurs. So the search string is 0wh.*0subj and I would like to find this search item plus 4 lines immediately before and after it. eg: xxx means whatever is on a new line. the search result should be: xxx xxx xxx xxx 0wh.*0subj xxx xxx xxx xxx I have tried using \n\r but its not working. Any assistance afforded would be greatly appreciated. Regards 回答1: This will work in Notepad++ (tested): (?m)(^[^\r\n]*\R+)

Regex to allow only number between 1 to 12

一曲冷凌霜 提交于 2019-12-21 17:40:16
问题 Regex to allow only number between 1 to 12 I am trying (12)|[1-9]\d? but its not working, please help as i am new to regular expression 回答1: Something like ^([1-9]|1[012])$ ^ Anchors the regex at start of the string [1-9] Matches 1 to 9 | Alternation, matches the previous match or the following match. 1[012] Matches 10 , 11 , or 12 $ Anchors the regex at the end of the string. Regex Demo 回答2: Try something like this: ^(1[0-2]|[1-9])$ 1[0-2] : first charcter must be 1 and second character can

What do we need Lookahead/Lookbehind Zero Width Assertions for?

南笙酒味 提交于 2019-12-20 10:40:03
问题 I've just learned about these two concepts in more detail. I've always been good with RegEx, and it seems I've never seen the need for these 2 zero width assertions. I'm pretty sure I'm wrong, but I do not see why these constructs are needed. Consider this example: Match a 'q' which is not followed by a 'u'. 2 strings will be the input: Iraq quit With negative lookahead, the regex looks like this: q(?!u) Without it, it looks like this: q[^u] For the given input, both of these regex give the

Converting a Regex Expression that works in Chrome to work in Firefox [duplicate]

做~自己de王妃 提交于 2019-12-20 07:56:04
问题 This question already has answers here : Javascript: negative lookbehind equivalent? (13 answers) Closed 6 months ago . I have this Regex Expression that works in chrome but doesn't not work in Firefox. SyntaxError: invalid regexp group It has something to do with lookbehinds and Firefox does not support these. I need this to work in Firefox can some one help me convert this so it works in Firefox and filters out the tags as well? return new RegExp(`(?!<|>|/|&amp|_)(?<!</?[^>]*|&[^;]*)(${term

Why the positive lookahead not working for this regex [closed]

徘徊边缘 提交于 2019-12-20 07:55:15
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 7 days ago . This is my regex ^(settings|issues(?=a))/$ I want to match settings/ and issuesa/ . The problem is I am only able to match settings/ and not issuesa/ . 回答1: The “a” in the lookahead is not part of the match. It would match if the regex was ^(settings|issues(?=a))a/$ (though it would not match settings/ then) or ^

Matching TV and Movie File names with Regex

℡╲_俬逩灬. 提交于 2019-12-20 05:40:39
问题 I've been working on getting a regular expression to grab the TV Show or Movie name, the year it was aired if it exist, the season #and the episode # from the file name of a video. I have a regular expression (below) that seems to work well for shows with double year dates (one of the years is in the show/movie name the other is the year it aired) for both movies and TV show. For TV Show it is able to grab the season and episode numbers if the format is in SXXEXX or XXX. I've been testing it

Parse commas not surrounded by brackets

我的梦境 提交于 2019-12-20 03:53:12
问题 The input is a comma-separated list of fields. Here is an example. tna,performance,ma[performance,3],price The issue is that some of the "fields" have parameters specified in square brackets and those parameters also have commas. What RegEx could I use to break a string like that on commas, only when they are outside of brackets. I want the end result to be tna performance ma[performance,3] price 回答1: This is what you need (?<!\[[\w,]*?), If brackets are nested within brackets, use this

replace characters in notepad++ BUT exclude characters inside single quotation marks

空扰寡人 提交于 2019-12-20 02:54:16
问题 I have a string in this kind: SELECT column_name FROM table_name WHERE column_name IN ('A' , 'stu' ,'Meyer', ....); I want replace all characters in notepad++ from upper to lower (or vice versa) BUT, exclude from replacement, characters inside single quotation marks. condition: It exists no solid structure before/behind the single quotation marks part! (That means - I can not use the keyword "IN" or signs like "," or "(" or ")" or ";" for this regex ...!) target string (the characters inside

PCRE: backreferences not allowed in lookbehinds?

雨燕双飞 提交于 2019-12-19 17:41:18
问题 The PCRE regex /..(?<=(.)\1)/ fails to compile: "Subpattern references are not allowed within a lookbehind assertion." Interestingly it seems to be acceptable in lookaheads, like /(?=(.)\1)../ , just not in lookbehinds. Is there a technical reason why backreferences are not allowed in lookbehinds specifically? 回答1: With Python's re module, group references are not supported in lookbehind, even if they match strings of some fixed length. Lookbehinds doesn't fully support PCRE rules. Concretely