Questions tagged [capturing-group]

Capturing groups are regular expression constructs that makes use of capturing in regex to capture parts of the matched string during a match sequence in the regexp pattern.

Capturing groups and s are regular expression constructs that makes use of capturing in to perform matching and replacement that remembers parts of the matched string during a match sequence in the regexp pattern.

Read more:

223 questions
0
votes
1 answer

Extract North American postal code using regex

I have the following regex that I use to validate North American postal codes: (?:(\d{5})(?:-\d{4})?)|(?:([a-zA-Z]\d[a-zA-Z]) ?(\d[a-zA-Z]\d)) FYI, I understand that it could be more exact, in regards to verifying certain characters in certain…
shannon
  • 8,664
  • 5
  • 44
  • 74
0
votes
5 answers

Regex fails to capture all groups

Using java.util.regex (jdk 1.6), the regular expression 201210(\d{5,5})Test applied to the subject string 20121000002Test only captures group(0) and does not capture group(1) (the pattern 00002) as it should, given the code below: Pattern p1 =…
user1761680
-1
votes
4 answers

How can I achieve this regex without a look ahead assertion?

I have regex which uses a look ahead assertion to match strings of the format {{ x }}. The regex is /(?<=\{\{\s)[^}\s]+(?=\s*\}\})/gm How can I achieve this without using a look ahead assertion?
williamsandonz
  • 15,864
  • 23
  • 100
  • 186
-1
votes
2 answers

How to extract content in between an opening and a closing bracket?

I am trying to split a string into an array of text contents which each are present within the [@ and ] delimiters. Just characters in between [@and ] are allowed to match. Being provided with a string like ... const stringA = '[@Mary James],…
Sonali
  • 3
  • 2
-1
votes
1 answer

Regex non-greedy named capturing groups

I need to parse the below text and read the value for id and name, and name is optional. I am getting 'txt" name="thistext' as the value for id. input id="txt" name="thistext" This is the regex I am using -…
Indu
  • 119
  • 1
  • 1
  • 5
-1
votes
2 answers

Scala - Explanation for regex statement

Assuming I have a dataframe called df and regex as follows: var df2 = df regex = new Regex("_(.)") for (col <- df.columns) { df2 = df2.withColumnRenamed(col, regex.replaceAllIn(col, { M => M.group(1).toUpperCase })) } I know that this…
activelearner
  • 7,055
  • 20
  • 53
  • 94
-1
votes
1 answer

Why doesn't this RegExp work as expected?

I made a RegExp to format an incoming date string, but it doesn't work as expected with my usage. I was hoping someone could explain why not: var data = [ "m_2013_01_01", "m_2013_02_01", "m_2013_03_01", "m_2013_04_01" ]; // why…
Patrick Roberts
  • 49,224
  • 10
  • 102
  • 153
-1
votes
1 answer

match doesn't return capturing group

I'm trying to apply a regular expression to a string, in search of any placeholders, but I can't figure out why the result is only the full match, not the capturing group. //----HTML------------------------//

Let's try…

WoodrowShigeru
  • 1,418
  • 1
  • 18
  • 25
-1
votes
1 answer

Using two capturing groups with JavaScript's replace() function

Given such a string +as[23+"AS@D"-@] replace all instances of @ between the [ and ] with the number right after the [ (in this case: 23). Please answer using JavaScript (a suggestion is using .replace()). So using this algorithm, +as[23+"AS@D"-@]…
user41805
  • 523
  • 1
  • 9
  • 21
-2
votes
2 answers

Regex - Capture after 2nd occurance of character

I have a list of numbers 1.01.01.01 1.01.01.02 1.01.02.03 I need to add 1 to the number after the 2nd occurance of '.0': 1.01.02.01 1.01.02.02 1.01.03.03 I am using javascript. I have tried a few things, but I just get so confused with regex…
Brendonius
  • 109
  • 3
-2
votes
1 answer

Intellij Search Regex, select specific capture group

I'm playing regex with intellij for the moment and I want to know if it's possible to use capture to select all occurrence of a specific group. 12 330 13 450 1223 870 1213 900 regex: (^\d+) (\d+) and select the 330 450 870 900 which are in…
MaskedHawk
  • 11
  • 3
-3
votes
1 answer

How to parse and distinguish different and varying arguments of a user command with a regular expression?

I'm trying to interpret user commands as dash optional flag. {run -o -f -a file1 file2} Something like this: /{run (-o|-f) (\w+) (.+?)}/g; Is very limiting with only 1 choice of flag. I'm looking for a regex that can properly parse the string with…
Harry
  • 52,711
  • 71
  • 177
  • 261
-3
votes
1 answer

Regex [] vs () in Python with respect to re.split()

What is the difference between [,.] and (,|.) when used as a pattern in re.split(pattern,string)? Can some please explain with respect to this example in Python: import re regex_pattern1 = r"[,\.]" regex_pattern2 =…
1 2 3
14
15