capturing-group

Vim Regex Capture Groups [bau -> byau : ceu -> cyeu]

≯℡__Kan透↙ 提交于 2019-11-28 02:56:19
I have a list of words: bau ceu diu fou gau I want to turn that list into: byau cyeu dyiu fyou gyau I unsuccessfully tried the command: :%s/(\w)(\w\w)/\1y\2/g Given that this doesn't work, what do I have to change to make the regex capture groups work in Vim? One way to fix this is by ensuring the pattern is enclosed by escaped parentheses: :%s/\(\w\)\(\w\w\)/\1y\2/g Slightly shorter (and more magic -al) is to use \v , meaning that in the pattern after it all ASCII characters except '0'-'9' , 'a'-'z' , 'A'-'Z' and '_' have a special meaning: :%s/\v(\w)(\w\w)/\1y\2/g See: :help \( :help \v If

Regex only capturing last instance of capture group in match

痴心易碎 提交于 2019-11-28 01:17:57
I have the following regular expression in two different languages that produces the same odd results (javaScript and Flash). What I want to know is not how to fix it, but why the behavior is occurring? The Regular Expression: \[(\\{2}|\\\]|[^\]])*\] The goal here is to match a bracketed string, and ensure that I don't stop at an escaped bracket. If I have the text input [abcdefg] it is correctly matched, but the only thing returned as part of the capture group is g , where as I expect abcdefg . If I change the expression to \[((?:\\{2}|\\\]|[^\]])*)\] , then I get the result that I want. So

How does this regex find triangular numbers?

与世无争的帅哥 提交于 2019-11-27 17:10:27
Part of a series of educational regex articles, this is a gentle introduction to the concept of nested references. The first few triangular numbers are: 1 = 1 3 = 1 + 2 6 = 1 + 2 + 3 10 = 1 + 2 + 3 + 4 15 = 1 + 2 + 3 + 4 + 5 There are many ways to check if a number is triangular. There's this interesting technique that uses regular expressions as follows: Given n , we first create a string of length n filled with the same character We then match this string against the pattern ^(\1.|^.)+$ n is triangular if and only if this pattern matches the string Here are some snippets to show that this

Get index of each capture in a JavaScript regex

荒凉一梦 提交于 2019-11-27 13:08:55
I want to match a regex like /(a).(b)(c.)d/ with "aabccde" , and get the following information back: "a" at index = 0 "b" at index = 2 "cc" at index = 3 How can I do this? String.match returns list of matches and index of the start of the complete match, not index of every capture. Edit: A test case which wouldn't work with plain indexOf regex: /(a).(.)/ string: "aaa" expected result: "a" at 0, "a" at 2 Note: The question is similar to Javascript Regex: How to find index of each subexpression? , but I cannot modify the regex to make every subexpression a capturing group. So, you have a text

Vim Regex Capture Groups [bau -> byau : ceu -> cyeu]

戏子无情 提交于 2019-11-26 23:53:30
问题 I have a list of words: bau ceu diu fou gau I want to turn that list into: byau cyeu dyiu fyou gyau I unsuccessfully tried the command: :%s/(\w)(\w\w)/\1y\2/g Given that this doesn't work, what do I have to change to make the regex capture groups work in Vim? 回答1: One way to fix this is by ensuring the pattern is enclosed by escaped parentheses: :%s/\(\w\)\(\w\w\)/\1y\2/g Slightly shorter (and more magic -al) is to use \v , meaning that in the pattern after it all ASCII characters except '0'-

Is there a regex flavor that allows me to count the number of repetitions matched by the * and + operators?

寵の児 提交于 2019-11-26 23:16:35
Is there a regex flavor that allows me to count the number of repetitions matched by the * and + operators? I'd specifically like to know if it's possible under the .NET Platform. You're fortunate because in fact .NET regex does this (which I think is quite unique). Essentially in every Match , each Group stores every Captures that was made. So you can count how many times a repeatable pattern matched an input by: Making it a capturing group Counting how many captures were made by that group in each match You can iterate through individual capture too if you want! Here's an example: Regex r =

Regex only capturing last instance of capture group in match

≡放荡痞女 提交于 2019-11-26 21:52:40
问题 I have the following regular expression in two different languages that produces the same odd results (javaScript and Flash). What I want to know is not how to fix it, but why the behavior is occurring? The Regular Expression: \[(\\{2}|\\\]|[^\]])*\] The goal here is to match a bracketed string, and ensure that I don't stop at an escaped bracket. If I have the text input [abcdefg] it is correctly matched, but the only thing returned as part of the capture group is g , where as I expect

How does this regex find triangular numbers?

泄露秘密 提交于 2019-11-26 18:55:47
问题 Part of a series of educational regex articles, this is a gentle introduction to the concept of nested references. The first few triangular numbers are: 1 = 1 3 = 1 + 2 6 = 1 + 2 + 3 10 = 1 + 2 + 3 + 4 15 = 1 + 2 + 3 + 4 + 5 There are many ways to check if a number is triangular. There's this interesting technique that uses regular expressions as follows: Given n , we first create a string of length n filled with the same character We then match this string against the pattern ^(\1.|^.)+$ n

Get index of each capture in a JavaScript regex

匆匆过客 提交于 2019-11-26 17:40:22
问题 I want to match a regex like /(a).(b)(c.)d/ with "aabccde" , and get the following information back: "a" at index = 0 "b" at index = 2 "cc" at index = 3 How can I do this? String.match returns list of matches and index of the start of the complete match, not index of every capture. Edit: A test case which wouldn't work with plain indexOf regex: /(a).(.)/ string: "aaa" expected result: "a" at 0, "a" at 2 Note: The question is similar to Javascript Regex: How to find index of each subexpression

Is there a regex flavor that allows me to count the number of repetitions matched by the * and + operators?

倖福魔咒の 提交于 2019-11-26 08:37:31
问题 Is there a regex flavor that allows me to count the number of repetitions matched by the * and + operators? I\'d specifically like to know if it\'s possible under the .NET Platform. 回答1: You're fortunate because in fact .NET regex does this (which I think is quite unique). Essentially in every Match , each Group stores every Captures that was made. So you can count how many times a repeatable pattern matched an input by: Making it a capturing group Counting how many captures were made by that