regex-group

C# Regex - Trying to get all the Tab character enclosed within double quotes

守給你的承諾、 提交于 2019-12-01 21:02:44
问题 In the end, I will want to replace all the \t that are enclosed within " I'm currently on Regex101 trying various iterations of my regex... This is the the closest I have so far... originString = blah\t\"blah\tblah\"\t\"blah\"\tblah\tblah\t\"blah\tblah\t\tblah\t\"\t\"\tbleh\" regex = \t?+\"{1}[^"]?+([\t])?+[^"]?+\" \t?+ maybe one or more tab \"{1} a double quote [^"]?+ anything but a double quote ([\t])?+ capture all the tabs [^"]?+ anything but a double quote \"{1} a double quote My logic is

C# Regex - Trying to get all the Tab character enclosed within double quotes

蓝咒 提交于 2019-12-01 19:03:16
In the end, I will want to replace all the \t that are enclosed within " I'm currently on Regex101 trying various iterations of my regex... This is the the closest I have so far... originString = blah\t\"blah\tblah\"\t\"blah\"\tblah\tblah\t\"blah\tblah\t\tblah\t\"\t\"\tbleh\" regex = \t?+\"{1}[^"]?+([\t])?+[^"]?+\" \t?+ maybe one or more tab \"{1} a double quote [^"]?+ anything but a double quote ([\t])?+ capture all the tabs [^"]?+ anything but a double quote \"{1} a double quote My logic is flawed! I need your help in grouping the tab characters. Match the double quoted substrings with a

Difference of regex in python and google app script (backend engine related?)

牧云@^-^@ 提交于 2019-12-01 12:56:19
I tried the same regular expression both in python (3.6, jupyter notebook) and Google app script, but it seems like "non-capturing group" is not working in the app script case. # python script: import re text='<a class=""email"" href=""mailto:SOisAwesome@hello.edu"">' regex='(?:<a class=""email"" href=""mailto:)(.+?@hello\.edu)(?:"">)' match=re.search(regex,text) print(match.group(1)) # result is 'SOisAwesome@hello.edu' // Google app script function myFunction() { string='<a class=""email"" href=""mailto:SOisAwesome@hello.edu"">' regex=new RegExp('(?:<a class=""email"" href=""mailto:)(.+?

Difference of regex in python and google app script (backend engine related?)

…衆ロ難τιáo~ 提交于 2019-12-01 12:00:28
问题 I tried the same regular expression both in python (3.6, jupyter notebook) and Google app script, but it seems like "non-capturing group" is not working in the app script case. # python script: import re text='<a class=""email"" href=""mailto:SOisAwesome@hello.edu"">' regex='(?:<a class=""email"" href=""mailto:)(.+?@hello\.edu)(?:"">)' match=re.search(regex,text) print(match.group(1)) # result is 'SOisAwesome@hello.edu' // Google app script function myFunction() { string='<a class=""email""

How exactly does this recursive regex work?

穿精又带淫゛_ 提交于 2019-12-01 06:08:39
This is a followup to this question . Have a look at this pattern: (o(?1)?o) It matches any sequence of o with a length of 2 n , with n ≥ 1. It works, see regex101.com (word boundaries added for better demonstration). The question is: Why? In the following, the description of a string (match or not) will simply be a bolded number or a bolded term that describes the length, like 2 n . Broken down (with added whitespaces): ( o (?1)? o ) ( ) # Capture group 1 o o # Matches an o each at the start and the end of the group # -> the pattern matches from the outside to the inside. (?1)? # Again the

C++11 regex: digit after capturing group in replacement string

徘徊边缘 提交于 2019-12-01 02:50:55
My regex_replace expression uses group $1 right before a '0' character in the replacement string like so: #include <iostream> #include <string> #include <regex> using namespace std; int main() { regex regex_a( "(.*)bar(.*)" ); cout << regex_replace( "foobar0x1", regex_a, "$10xNUM" ) << endl; cout << regex_replace( "foobar0x1", regex_a, "$1 0xNUM" ) << endl; } The output is: xNUM foo 0xNUM I'm trying to get output foo0xNUM without the middle whitespace. How do I guard the group name $1 from the next character in the substitution string? Guvante You are allowed to either specify $n or $nn to

preg_replace how to replace only matching xxx($1)yyy pattern inside the selector

那年仲夏 提交于 2019-11-30 10:57:17
问题 I'm trying to use a regular expression to erase only the matching part of an string. I'm using the preg_replace function and have tried to delete the matching text by putting parentheses around the matching portion. Example: preg_replace('/text1(text2)text3/is','',$html); This replaces the entire string with '' though. I only want to erase text2, but leave text1 and text3 intact. How can I match and replace just the part of the string that matches? 回答1: There is an alternative to using text1

preg_replace how to replace only matching xxx($1)yyy pattern inside the selector

一曲冷凌霜 提交于 2019-11-29 22:58:21
I'm trying to use a regular expression to erase only the matching part of an string. I'm using the preg_replace function and have tried to delete the matching text by putting parentheses around the matching portion. Example: preg_replace('/text1(text2)text3/is','',$html); This replaces the entire string with '' though. I only want to erase text2, but leave text1 and text3 intact. How can I match and replace just the part of the string that matches? There is an alternative to using text1 and text3 in the match pattern and then putting them back in via the replacement string. You can use

functional difference between lookarounds and non-capture group?

北慕城南 提交于 2019-11-29 14:19:49
问题 I'm trying to come up with an example where positive look-around works but non-capture groups won't work, to further understand their usages. The examples I"m coming up with all work with non-capture groups as well, so I feel like I"m not fully grasping the usage of positive look around. Here is a string, (taken from a SO example) that uses positive look ahead in the answer. The user wanted to grab the second column value, only if the value of the first column started with ABC, and the last

Powershell - Regular Expression Multiple Matches

情到浓时终转凉″ 提交于 2019-11-29 11:01:12
Maybe my reasoning is faulty, but I can't get this working. Here's my regex: (Device\s#\d(\n.*)*?(?=\n\s*Device\s#|\Z)) Try it: http://regex101.com/r/jQ6uC8/6 $getdevice is the input string. I'm getting this string from the Stream/Output from a command line tool. $dstate = $getdevice | select-string -pattern '(Device\s#\d(\n.*)*?(?=\n\s*SSD\s+|\Z))' -AllMatches | % { $_ -match '(Device\s#\d(\n.*)*?(?=\n\s*SSD\s+|\Z))' > $null; $matches[0] } Write-Host $dstate Output: Device #0 Device #1 Device #2 Device #3 Device #4 Same output for the $matches[1], $matches[2] is empty. Is there a way I can