capture-group

Regex: capturing groups within capture groups

▼魔方 西西 提交于 2019-12-04 10:53:25
问题 Intro (you can skip to What if... if you get bored with intros) This question is not directed to VBScript particularly (I just used it in this case): I want to find a solution for general regular expressions usage (editors included). This started when I wanted to create an adaptation of Example 4 where 3 capture groups are used to split data across 3 cells in MS Excel. I needed to capture one entire pattern and then, within it, capture 3 other patterns. However, in the same expression, I also

How to optionally add a comma and whitespace to a capture group?

别等时光非礼了梦想. 提交于 2019-12-04 05:07:07
问题 I am trying to match five substrings in each block of text (there are 100 blocks total). I am matching 99% of the blocks of text, but with a few errors regarding groups 3 and 4. Here is a demo link: https://regex101.com/r/cW2Is3/4 Group 3 is "parts of speech", and group 4 is an English translation. In the first block of text, det, pro should all be in group 3, and then the; him, her, it, them should be in group 4. The same issue occurs again in the third block of text. Group 3 should be adj,

C++11 Regex Capture Groups By Name

最后都变了- 提交于 2019-12-03 11:50:36
I am converting my boost-based regular expressions to C++11 regex. I have a capture group called url : \s*?=\s*?(("(?<url>.*?)")|('?<url>.*?)')) With boost, if you had an smatch you could call match.str("url") to get the capture group by name. With std::smatch , I am only seeing indexed sub-matches. How can I get access to the url capture using the std::smatch class? You cannot name a capture group with the c++11 standard. C++11 regex conforms to the ECMAScript syntax. Here is a link that explains it all http://www.cplusplus.com/reference/regex/ECMAScript/ . Even though this maybe

How to optionally add a comma and whitespace to a capture group?

不羁岁月 提交于 2019-12-02 04:37:17
I am trying to match five substrings in each block of text (there are 100 blocks total). I am matching 99% of the blocks of text, but with a few errors regarding groups 3 and 4. Here is a demo link: https://regex101.com/r/cW2Is3/4 Group 3 is "parts of speech", and group 4 is an English translation. In the first block of text, det, pro should all be in group 3, and then the; him, her, it, them should be in group 4. The same issue occurs again in the third block of text. Group 3 should be adj, det, nm, pro and Group 4 should be a, an, one . This is my pattern: ([0-9]+)\s+(\w+(?:, \w+)?)\s+(\N+?)

Get $1 capture group with dynamic RegExp

风格不统一 提交于 2019-12-01 23:10:00
问题 I was curious if anyone knows what I'm doing wrong here. I want to use a variable inside the expression but for some reason when I try to, it doesn't seem to grab the search term with the $1 . This returns correctly: $('.content').html(function(_,i) { return i.replace(/(cat)/gi, '<span class="highlight">$1</span>'); }); For some reason, this does not: $('.content').html(function(_,i) { var customVariable = 'cat'; var pattern = new RegExp(customVariable,'gi'); return i.replace(pattern, '<span

java regex - capture repeated groups

拈花ヽ惹草 提交于 2019-12-01 12:39:17
问题 I'm using Java's regex library. I want to validate a string against the following format: 31,5,46,7,86(...) The amount of numbers is not known. I want to make sure there is at least one number in that string, and that every two numbers are separated by a comma. I also want to get the numbers from the string. ( Note: this is just a simplified example, string.split will not solve my actual problem) I wrote the following regex: ({[0-9]++)((?:,[0-9]++)*+) The validation part works. However, when

Regex to capture unknown number of repeated groups

旧时模样 提交于 2019-12-01 07:24:50
问题 I'm try to write a regular expression to use in a Java program that will recognize a pattern that may appear in the input an unknown number of times. My silly little example is: String patString = "(?:.*(h.t).*)*"; Then I try to access the matches from a line like "the hut is hot" by looping through matcher.group(i). It only remembers the last match (in this case, "hot") because there is only one capture group--I guess the contents of matcher.group(1) get overwritten as the capture group is

Why won't re.groups() give me anything for my one correctly-matched group?

↘锁芯ラ 提交于 2019-11-29 10:41:39
问题 When I run this code: print re.search(r'1', '1').groups() I get a result of () . However, .group(0) gives me the match. Shouldn't groups() give me something containing the match? Update: Thanks for the answers. So that means if I do re.search() with no subgroups, I have to use groups(0) to get a match? 回答1: groups is empty since you do not have any capturing groups - http://docs.python.org/library/re.html#re.MatchObject.groups. group(0) will always returns the whole text that was matched

Regex - Repeating Capturing Group

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 10:12:43
I'm trying to figure out how I can repeat a capture group on the comma-separated values in this the following url string: id=1,2;name=user1,user2,user3;city=Oakland,San Francisco,Seattle;zip=94553,94523; I'm using this RegExp which is return results I want, except for the values since they're dynamic ie. could be 2,3,4,etc users in the url parameter and was wondering if I could create a capture group for each value instead of user1,user2,user3 as one capture-group. RegExp: (^|;|:)(\w+)=([^;]+)* Here is a live demo of it online using RegExp Example Output: Group1 - (semi-colon,colon) Group2 -

Capture groups not working in NSRegularExpression

故事扮演 提交于 2019-11-28 04:53:04
Why is this code only spitting out the entire regex match instead of the capture group? Input @"A long string containing Name:</td><td>A name here</td> amongst other things" Output expected A name here Actual output Name:</td><td>A name here</td> Code NSString *htmlString = @"A long string containing Name:</td><td>A name here</td> amongst other things"; NSRegularExpression *nameExpression = [NSRegularExpression regularExpressionWithPattern:@"Name:</td>.*\">(.*)</td>" options:NSRegularExpressionSearch error:nil]; NSArray *matches = [nameExpression matchesInString:htmlString options:0 range