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:

191 questions
0
votes
1 answer

REGEX: Getting information from a specific group which is surrounded by many optional groups

Suppose I have a regex expression that matches a string like this: (A)(B)?(C)(D)?(E)(F)? where the groups B, D, and F are optional. How can I get just group E? I ask this because, I don't think I can just call M.group(5) because if my matcher (M)…
0
votes
1 answer

how does this regex for email address validation work?

While searching for regular expressions used for email address validation, i came across this page: http://www.regular-expressions.info/email.html. i couldn't understand it. it says: \b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+.)+[A-Z]{2,4}\b will match…
burhan
  • 121
  • 1
  • 9
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,305
  • 5
  • 40
  • 69
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
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
  • 99
  • 1
  • 1
  • 5
-1
votes
2 answers

Capturing groups and Pattern split method in regular expression

How can I understand the output of the below code? The code's first four print statements are about the Capturing Groups in Regular Expression in Java and the rest of the code is about the Pattern split method. I referred a few documents to perceive…
Ram
  • 3,270
  • 4
  • 21
  • 48
-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
  • 5,115
  • 14
  • 42
  • 77
-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
  • 40,065
  • 5
  • 74
  • 116
-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
  • 992
  • 13
  • 17
-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
  • 503
  • 1
  • 9
  • 20
-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
12
13