regex-group

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

Regex named groups in R

浪尽此生 提交于 2019-12-20 01:42:35
问题 For all intents and purposes, I am a Python user and use the Pandas library on a daily basis. The named capture groups in regex is extremely useful. So, for example, it is relatively trivial to extract occurrences of specific words or phrases and to produce concatenated strings of the results in new columns of a dataframe. An example of how this might be achieved is given below: import numpy as np import pandas as pd import re myDF = pd.DataFrame(['Here is some text', 'We all love TEXT',

Regex optional group

戏子无情 提交于 2019-12-18 18:38:22
问题 I am using this regex: ((?:[a-z][a-z]+))_(\d+)_((?:[a-z][a-z]+)\d+)_(\d{13}) to match strings like this: SH_6208069141055_BC000388_20110412101855 separating into 4 groups: SH 6208069141055 BC000388 20110412101855 Question: How do I make the first group optional, so that the resulting group is a empty string? I want to get 4 groups in every case, when possible. Input string for this case: (no underline after the first group) 6208069141055_BC000388_20110412101855 回答1: You can easily simplify

regex to match two different groups with the same length

随声附和 提交于 2019-12-14 02:25:22
问题 I would like to construct a regex that matches two groups, with the second group consisting of a single character repeated the same number of times as the number of characters in the first group. Something like ^(\w+) (x{length of \1}) so, for example, hello xxxxx and foo xxx would match, but hello xxxxy and foo xxy would not. Is this possible? The goal here is to match indentation in reStructuredText-style lists, where the second line in a list item should be indented to match the start of

php capture group

六眼飞鱼酱① 提交于 2019-12-13 18:42:09
问题 I'm kind of stuck capturing a group with preg_match() in php. This is my pattern: <ns2:uniqueIds>(.*)<\/ns2:uniqueIds> And this is the source: <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"><env:Header/><env:Body><ns2:ListResponse xmlns:ns2="http://censored"><ns2:uniqueIds>censored</ns2:uniqueIds><ns2:uniqueIds>censored</ns2:uniqueIds></ns2:ListResponse></env:Body></env:Envelope> What am I missing? 回答1: While I agree with the people above that tell you to not use regular

regex to find variables surrounded by % in a string

醉酒当歌 提交于 2019-12-13 10:57:59
问题 Need to find "variables" within a string. What denotes a variable is %[/w]+%, the catch is there can be more than one variable within the string: %ABC% %ABC%-%RED% Lorem ipsum %GeT% sit amet, %% consectetur %QW23% elit. In the third example the %% should NOT be found, it will be replaced with a single %. Something like #[\w+-]+# does not work because it cannot determine that in the second line it is %ABC% and %RED%, but rather %-%. I am under the impression that both groups and back

what group does backreference refers to when used with sub() operation?

 ̄綄美尐妖づ 提交于 2019-12-13 04:01:24
问题 The following code: >>> text = "imagine a new *world*, a *magic* world" >>> pattern = re.compile(r'\*(.*?)\*') >>> pattern.sub(r"<b>\1<\b>", text) outputs: imagine a new <b>world<\x08>, a <\b>magic<\x08> world I have two problems here, 1.) I don't understand why does back reference '\1' changes the magic part of the text? I have read that '\1' refers to the first group which is captured. 2.) Why does <\b> outputs <\x08> even after using 'r' as prefix. I dosen't happen with '\n' . 回答1: sub

Is there a way to use a list of string parameters with a regular expression (with groups) to construct a new string?

烂漫一生 提交于 2019-12-13 02:11:27
问题 Let's say for example that I have a regular expression like this: "The quick (red|brown|blue|yellow) fox (jumps|leaps) over the lazy (dog|cat)." This regex has 3 grouped components - if it's matched against a given string, the regex api would allow you to easily extract the value inside each group. Now let's say I have 3 strings: ["red", "leaps","cat"] If we make the assumption that all the characters in the regex that are not inside groups are just literal text characters - is there a way to

PHP How to set the preg-groups to “non-capture” (?:…)

倾然丶 夕夏残阳落幕 提交于 2019-12-12 09:18:23
问题 In HTML page, I remove HTML comments like this $contentHTML = preg_replace("#(?=<!--)([\s\S]*?)-->#", "", $contentHTML); But on a huge page for preg_replace , I got " PHP Fatal error: Allowed memory size ... " Perhaps, one solution, would use the non-matching group to avoid capturing text? Could someone explain how use on-matching group ?: Or how can I suppress HTML comments in huge page without preg_replace ? 回答1: Just unroll the regex as $contentHTML = preg_replace("#<!--[^-]*(?:-(?!->)[^-]

How do I quantify a group in Javascript's regex? [duplicate]

痞子三分冷 提交于 2019-12-12 05:58:11
问题 This question already has answers here : JavaScript regular expressions and sub-matches (2 answers) Closed 5 years ago . Let's say I had a string "QQxaxbxcQQ", and I wanted to capture all groups of x followed by any character. I also only want to search between the QQ's (the string may include other things in it). I assumed this would have worked: var matches = str.match(/QQ(x\w)+QQ/) However, this only seems to return to me the last match (xc). Can you point me in the right direction? EDIT: