regex-lookarounds

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

和自甴很熟 提交于 2019-12-02 12:56:58
This question already has an answer here: Javascript: negative lookbehind equivalent? 13 answers 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})`, 'gi'); }; searchTermsInArray.forEach(term => { if (term.length) { const regexp = this.regexpFormula(term); newQuestion

Matching TV and Movie File names with Regex

♀尐吖头ヾ 提交于 2019-12-02 11:09:46
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 out in the regex101.com test engine. Where I'm struggling is the expression won't return anything if a

Splitting digits into groups of threes, from right to left using regular expressions

笑着哭i 提交于 2019-12-02 11:09:40
I have a string '1234567890' that I want split into groups of threes, starting from right to left, with the left most group ranging from one digit to 3-digits (depending on how many digits are left over) Essentially, it's the same procedure as adding commas to a long number, except, I also want to extract the last three digits as well. I tried using look-arounds but couldn't figure out a way to get the last three digits. string = '1234567890' re.compile(r'\d{1,3}(?=(?:\d{3})+$)') re.findall(pattern, string) ['1', '234', '567'] Expected output is (I don't need commas): ['1', '234', '567', 789]

Python regex: Following lookahead with quantifier

自作多情 提交于 2019-12-02 10:54:40
Just trying to wrap my mind around this question, which occurred to me while I was messing around with positive lookaheads. Does this regex make any sense? foo(?=bar)+ re.match() doesn't return an error, but if there's any sense to the '+' quantifier, I can't figure what it would be. (FWIW, regex101.com gives the error 'The preceding token is not quantifiable' ...) Thanks. /John There is no reason to use the + quantifier here. Regular expression lookaheads and lookbehinds don't actually match any text , which means that if they match once in a position they will "match" an infinite number of

Capture groups match with quantifier Regexp

假如想象 提交于 2019-12-02 09:30:23
I am newbie in regex world, I need to capture some different types of strings. By the way please suggest more elagant way to capture such strings. n = any positive number(not the same) |n||0||0||0||0| |n||n||0||0||0| |n||n||n||0||0| |n||n||n||n||0| |n||n||n||n||n| I have tried to use such regular expression for capturing first and secodn types of strings ^\|([1-9]+)\|(?:([1-9]+)\|){4}|(?:(0)\|){4}$ Zero should be treated as separate char, I need to capture each number or zero The problem now that it only captures first matched character and last one But doesn't capture other digits Please help

Python: consecutive lines between matches similar to awk

匆匆过客 提交于 2019-12-02 05:11:55
问题 Given: A multiline string string (already read from a file file ) Two patterns pattern1 and pattern2 which will match a substring of exactly one line in string each. These lines will be called line1 and line2. The patterns are regex-patterns, but I can change their format if that makes it easier. Searched I am looking for a way to get all the lines between line1 and line2 in python (we can safely assume that line1 is before line2). Of course this could be done in a for loop with a flag set by

Parse commas not surrounded by brackets

落花浮王杯 提交于 2019-12-02 03:25:13
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 Anirudha This is what you need (?<!\[[\w,]*?), If brackets are nested within brackets, use this because the above would fail in that scenario.. (?<!\[[\w,]*?),(?![\w,]*?\]) works here Try this : "[a

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

戏子无情 提交于 2019-12-01 23:24:25
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 single quotation marks have to stay unchangend): select column_name from table_name where column_name

Python: consecutive lines between matches similar to awk

安稳与你 提交于 2019-12-01 23:20:17
Given: A multiline string string (already read from a file file ) Two patterns pattern1 and pattern2 which will match a substring of exactly one line in string each. These lines will be called line1 and line2. The patterns are regex-patterns, but I can change their format if that makes it easier. Searched I am looking for a way to get all the lines between line1 and line2 in python (we can safely assume that line1 is before line2). Of course this could be done in a for loop with a flag set by pattern1 and a break when pattern2 matches. I am looking for a more compact solution here, though.

PCRE: backreferences not allowed in lookbehinds?

孤街醉人 提交于 2019-12-01 17:46:41
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? 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, when the regex engine reaches a lookbehind it'll try to determine it size, and then jump back to check the