backreference


Negating a backreference in Regular Expressions

纵饮孤独 提交于 2020-01-14 06:47:12
问题 if a string has this predicted format: value = "hello and good morning" Where the " (quotations) might also be ' (single quote), and the closing char (' or ") will be the same as the opening one. I want to match the string between the quotation marks. \bvalue\s*=\s*(["'])([^\1]*)\1 (the two \s are to allow any spaces near the = sign) The first "captured group" (inside the first pair of brackets) - should match the opening quotation which should be either ' or " then - I'm supposed to allow

How to replace all the blanks within square brackets with an underscore using sed?

对着背影说爱祢 提交于 2020-01-02 10:20:34
问题 I figured out that in order to turn [some name] into [some_name] I need to use the following expression: s/\(\[[^ ]*\) /\1_/ i.e. create a backreference capture for anything that starts with a literal '[' that contains any number of non space characters, followed by a space, to be replaced with the non space characters followed by an underscore. What I don't know yet though is how to alter this expression so it works for ALL underscores within the braces e.g. [a few words] into [a_few_words].

Java Regex - capture string with single dollar, but not when it has two successive ones

一笑奈何 提交于 2020-01-02 08:16:22
问题 I posted this question earlier. But that wasn't quite the end of it. All the rules that applied there still apply. So the strings: "%ABC%" would yield ABC as a result (capture stuff between percent signs) as would "$ABC." (capture stuff after $, giving up when another dollar or dot appears) "$ABC$XYZ" would too, and also give XYZ as a result. To add a bit more to this: "${ABC}" should yield ABC too. (ignore curly braces if present - non capture chars perhaps?). if you have two successive

How to apply a function on a backreference?

跟風遠走 提交于 2019-12-30 07:06:08
问题 Say I have strings like the following: old_string = "I love the number 3 so much" I would like to spot the integer numbers (in the example above, there is only one number, 3 ), and replace them with a value larger by 1, i.e., the desired result should be new_string = "I love the number 4 so much" In Python, I can use: r = re.compile(r'([0-9])+') new_string = r.sub(r'\19', s) to append a 9 at the end of the integer numbers matched. However, I would like to apply something more general on \1 .

How to backreference in Ruby regular expression (regex) with gsub when I use grouping?

你说的曾经没有我的故事 提交于 2019-12-29 03:53:06
问题 I would like to patch some text data extracted from web pages. sample: t="First sentence. Second sentence.Third sentence." There is no space after the point at the end of the second sentence. This sign me that the 3rd sentence was in a separate line (after a br tag) in the original document. I want to use this regexp to insert "\n" character into the proper places and patch my text. My regex: t2=t.gsub(/([.\!?])([A-Z1-9])/,$1+"\n"+$2) But unfortunately it doesn't work: "NoMethodError:

%N backreference inside RewriteCond

一个人想着一个人 提交于 2019-12-28 10:10:34
问题 I'm working on a virtual domain system. I have a wildcard DNS set up as *.loc , and I'm trying to work on my .htaccess file. The following code works: RewriteEngine On RewriteCond %{HTTP_HOST} ^(www.)?example\.loc$ [NC] RewriteCond %{REQUEST_URI} !^/example/ RewriteRule (.*) /example/$1 [L,QSA] But, I want this to work with anything I put in. However, I need the %{REQUEST_URI} checked against the text found as the domain. I tried using this code: RewriteEngine On RewriteCond %{HTTP_HOST} ^

%N backreference inside RewriteCond

霸气de小男生 提交于 2019-12-28 10:10:12
问题 I'm working on a virtual domain system. I have a wildcard DNS set up as *.loc , and I'm trying to work on my .htaccess file. The following code works: RewriteEngine On RewriteCond %{HTTP_HOST} ^(www.)?example\.loc$ [NC] RewriteCond %{REQUEST_URI} !^/example/ RewriteRule (.*) /example/$1 [L,QSA] But, I want this to work with anything I put in. However, I need the %{REQUEST_URI} checked against the text found as the domain. I tried using this code: RewriteEngine On RewriteCond %{HTTP_HOST} ^

Can you use back references in the pattern part of a regular expression?

人盡茶涼 提交于 2019-12-23 19:36:05
问题 Is there a way to back reference in the regular expression pattern? Example input string: Here is "some quoted" text. Say I want to pull out the quoted text, I could create the following expression: "([^"]+)" This regular expression would match some quoted . Say I want it to also support single quotes, I could change the expression to: ["']([^"']+)["'] But what if the input string has a mixture of quotes say Here is 'some quoted" text. I would not want the regex to match. Currently the regex

Why not create a backreference?

大城市里の小女人 提交于 2019-12-23 13:39:05
问题 I understand that putting ?: inside of the start of the parentheses of a regular expression will prevent it from creating a backreference, which is supposed to be faster. My question is, why do this? Is the speed increase noticeable enough to warrant this consideration? Under what circumstances is it going to matter so much that you need to carefully skip the backreference each time you are not going to use it. Another disadvantage is that it makes the regex harder to read, edit, and update

Why not create a backreference?

断了今生、忘了曾经 提交于 2019-12-23 13:38:07
问题 I understand that putting ?: inside of the start of the parentheses of a regular expression will prevent it from creating a backreference, which is supposed to be faster. My question is, why do this? Is the speed increase noticeable enough to warrant this consideration? Under what circumstances is it going to matter so much that you need to carefully skip the backreference each time you are not going to use it. Another disadvantage is that it makes the regex harder to read, edit, and update

工具导航Map