Questions tagged [regex-group]

Regex groups are created by placing part of a regular expression inside parentheses. Groups allows to apply a quantifier to the entire group or to restrict alternation to part of the regex. Besides grouping part of a regular expression together, parentheses also create a numbered capturing group. It stores the part of the string matched by the part of the regular expression inside the parentheses.

The regex Set(Value)? matches Set or SetValue. In the first case, the first (and only) capturing group remains empty. In the second case, the first capturing group matches Value.

If capturing the match isn't needed, the regular expression can be optimized into Set(?:Value)?. The question mark and the colon after the opening parenthesis are the syntax that creates a non-capturing group.

The question mark after the opening bracket is unrelated to the question mark at the end of the regex. The final question mark is the quantifier that makes the previous token optional. This quantifier cannot appear after an opening parenthesis, because there is nothing to be made optional at the start of a group. Therefore, there is no ambiguity between the question mark as an operator to make a token optional and the question mark as part of the syntax for non-capturing groups.

2670 questions
0
votes
1 answer

Remove a set of specific characters from a string using Regular Expression

How to remove all the occurrences of apostrophe('), hyphen(-) and dot(.) in a given string using Regular Expression? For example: John,. Home'Owner-New should return John, HomeOwnerNew I have tried using name.replace("\'", "").replace("-",…
0
votes
1 answer

How do I create a regex that continues to match only if there is a comma or " and " after the last one?

What this code does is extract a verb and the information that follows after it. Then create a .txt file with the name of the verb and write the information inside. I have to run to win the race import re, os regex_patron_01 = r"\s*\¿?(?:have…
user18051870
0
votes
2 answers

Is there a method to get all groups in regular expression with wildcard in python

Just like the follow code, there is not all groups. Is there a method to get all groups? Thanks~ import re res = re.match(r'(?: ([a-z]+) ([0-9]+))*', ' a 1 b 2 c 3') # echo ('c', '3'), but I want ('a', '1', 'b', '2', 'c', '3') res.groups()
Yuebo Guo
  • 5
  • 3
0
votes
0 answers

JS Regex - non-capturing group not working

I am working on a regex filter, because it clutters our code, but I cant get it to stop capturing the tags. What I want captured is bold
0
votes
1 answer

Nginx rewrite regex to rewrite root and subdirectory

Currently i have server { listen 8080; server_name default; location /foo/ { rewrite ^/foo(/.*)$ $1 break; proxy_redirect https://example.com https://$host/; } This matches foo and essentially strips it. I need to…
Alex
  • 152
  • 6
0
votes
2 answers

Matching pattern repeats for unknown times. How to replace each matched string?

I have this string mark:: string1, string2, string3 I want it to be mark:: xxstring1xx, xxstring2xx, xxstring3xx The point is, I don't know how many times the matched string repeated. Sometimes there are 10 strings in the line, sometimes there is…
Ooker
  • 1,969
  • 4
  • 28
  • 58
0
votes
1 answer

RegEx - Capturing according to a pattern that matches EVEYTHING.. BUT the repetition of the beginning of the pattern

I struggle with my regex pattern and I need some help. I'm trying to scrape some javascript content to capture label and value pairs. I started with this "label" : "(.*)"[\s\S]*?"value" : "(.*)" to scrape something like this "label" : "Something…
calandos
  • 3
  • 1
0
votes
5 answers

Regex: select until first space or comma occurrence

I have following example of american addresses. 6301 Stonewood Dr Apt-728, Plano TX-75024 13323 Maham Road, Apt # 1621, Dallas, TX 75240 17040 Carlson Drive, #1027 Parker, CO 80134 3465 25th St., San Francisco, CA 94110 I want to extract city…
Wasim
  • 7
  • 7
0
votes
1 answer

Extracting 'year' from a column

I have a working code, but I think my logic isn't on the right path (although it works). I just need some help with optimizing it. Essentially, to see if what I did was an acceptable way of doing what I am doing or if there's a better way. I am…
Anonymous Person
  • 1,437
  • 8
  • 26
  • 47
0
votes
1 answer

regex stl ECMAScript extremly slow

I had a question, I'm using std::regex with these params : const std::regex_constants::syntax_option_type grammar = std::regex_constants::ECMAScript; const std::regex_constants::syntax_option_type optionNonICase = grammar |…
X6Entrepreneur
  • 971
  • 2
  • 10
  • 30
0
votes
1 answer

How do I use regex inside my TensorFlow TextVectorization(split=)?

I have a regex tokenizer: import re HTML_SCANNER_REGEX = re.compile(r'
Dave Babbitt
  • 1,038
  • 11
  • 20
0
votes
1 answer

Java Regex: capture group between two characters and then match character within captured group

Question: How can I first capture a group(s) between two characters, and second match a character within that matched group(s)? Given Input: atribute="value1" AND atrribute="*value2" Problem 1: I want to capture a group between two characters,…
0
votes
2 answers

Regex expression to capture only numeric fields and strip $ and comma, no match if there are any alphanumeric

I'm trying to write a regex that will strip out $ and , from a value and not match at all if there are any other non-numerics. $100 -> 100 $12,203.00 -> 12203.00 12JAN2022 -> no match I have gotten sort of close with…
Dan
  • 304
  • 2
  • 10
0
votes
0 answers

Retrieve name from a matching named capturing group in Java/Kotlin regex

I have a Python application that tokenises a line using an RE for each token format. Say the formats were [0-9]+ or [A-Z][A-Z0-9]* or + they might get bundled into: (?P[0-9]+)|(?P[A-Z][A-Z0-9]*)|(?P\+) Assuming only one group matches a…
epoche
  • 409
  • 1
  • 4
  • 5
0
votes
0 answers

How to combine non-adjacent groups without using branch resets or capturing inside lookarounds?

Suppose I have the following text: # Should match - [ ] Some task - [ ] Some task | [[link]] - [ ] Some task ^abcdef - [ ] Some task | [[link]] ^abcdef - [ ] ! Some task - [ ] ! Some task | [[link]] - [ ] ! Some task ^abcdef - [ ] ! Some task |…
Mihai
  • 2,807
  • 4
  • 28
  • 53
1 2 3
99
100