backreference

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

Using more than nine back references in an R regex

半城伤御伤魂 提交于 2019-12-21 21:32:39
问题 The code below does not work, because the replacement string for \10, \11, and so on, cannot be read properly. It reads \10 as \1 and print 0 instead, can you help me fix it? There is an answer in one of the threads, saying that I am supposed to use capturing or naming groups, but I don't really understand how to use them. headline <- gsub("regexp with 10 () brackets", "\\1 ### \\2 ### \\3 ### \\4 ### \\5 ### \\6 ### \\7 ### \\8 ### \\9 ### \\10### \\11### \\12### \\13### \\14### \\15### \\16

Named backreferences with preg_replace

笑着哭i 提交于 2019-12-18 14:54:20
问题 Pretty straightforward; I can't seem to find anything definitive regarding PHP's preg_replace() supporting named backreferences: // should match, replace, and output: user/profile/foo $string = 'user/foo'; echo preg_replace('#^user/(?P<id>[^/]+)$#Di', 'user/profile/(?P=id)', $string); This is a trivial example, but I'm wondering if this syntax, (?P=name) is simply not supported. Syntactical issue, or non-existent functionality? 回答1: They exist: http://www.php.net/manual/en/regexp.reference

Regex backreference findall not working

断了今生、忘了曾经 提交于 2019-12-17 20:39:01
问题 I have recently been using regexes in a program. In this program I used them to find words in a list of words that matched a certain RE. However, when i tried backreferencing with this program, I got an interesting result. Here is the code: import re pattern = re.compile(r"[abcgr]([a-z])\1[ldc]") string = "reel reed have that with this they" print(re.findall(pattern, string)) What I expected was the result ["reel","reed"] (the regex matched these when I used it with Pythex) However, when I

Notepad++ Regex Backreference syntax in Search/Replace - \1 or $1

跟風遠走 提交于 2019-12-17 16:01:55
问题 I have tried to use the Notepad++ Search/Replace with a Regular Expression to replace specific words with shorter versions of those words. I used the following regex to match every word that ends with er (but not er as a word) - and replace the matching words with the same words minus the ending r , using a backreference: Find what: ([a-zA-z]+e)r Replace with: $1 But it doesn't replace the matching words, even though it finds them. However, if I change the backreference syntax to this: