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
3 answers

Regex Capture Middle Value

I would like to ask for your help... I have this string where I have to get the 4.75. I've tried many regex expression but I could not get it to work and been through browsing lots of examples as well. Regexr Image Loan Amount Interest…
kcodes
  • 1
  • 3
0
votes
1 answer

Regex for palindromes accepts non-palindrome 3-letters words

My regex should accept every palindrome for word length from 2 to 7 letters (without whitespaces). My regex looks like this: ^(\S?)(\S?)(\S?)\S?\3\2\1$ Can you explain to me what I did wrong during writing that regex and how can I fix it? For me…
0
votes
1 answer

How to remove extra parentheses, if and only if, in between they contain a regex pattern?

import re, datetime input_text = "hhhh ((44_-_44)) ggj ((2022_-_02_-_18 20:00 pm)) ((((2022_-_02_-_18 20:00 pm))) (2022_-_02_-_18 00:00 am)" identify_dates_regex_00 = r"(?P\d*)_-_(?P\d{2})_-_(?P\d{2})" identify_time_regex =…
Matt095
  • 857
  • 3
  • 9
0
votes
0 answers

Why does the re.sub method replace with the names of the capturing groups and not with the values that these groups should capture in input string?

import re, datetime #example input_text = "Alrededor de las 00:16 am o las 23:30 pm 2022_-_02_-_18 , quizas cerca del 2022_-_02_-_18 llega el avion, pero no a las (2022_-_02_-_18 00:16 am), de esos hay dos (22)" #identification…
Matt095
  • 857
  • 3
  • 9
0
votes
0 answers

Regex multiple exclusion alternatives and detection of MD5

I want to exclude some specific words and if those words doesn't match, then should match an md5 hash for example. Here a small log as example "value": "ef51be4506d7d287abc8c26ea6c495f6", "u_jira_status": "", "u_quarter_closed": "", "file_hash":…
RemDosal
  • 23
  • 4
0
votes
2 answers

Regex to find substring between 2 Strings excluding a specific String

I have checked all the existing questions on Stackoverflow but I couldn't find the perfect answer to it and need your help. So basically I have multiple Strings containing different formats of URL in different ways, for eg:- 1:

0
votes
0 answers

VBA Excel Regex Pattern

I need a pattern to extract data from a given string. I tried many patterns but I could get it. I request you to please help me to solve this issue. Input: B01ACE595E_B011GGG3DE=[color_name], B01ACE595E_B07P9J73RB=[color_name],…
0
votes
3 answers

Get every word ending with dot using Regex/VBA

I am using excel 2019 and I am trying to extract from a bunch of messed up text cells any (up to 5) word ending with dot that comes after a ]. This is a sample of the text I am trying to parse/clean ` some text [asred.] ost. |Monday - Ribben (ult.)…
Serbiss
  • 3
  • 6
0
votes
0 answers

Reorder this data obtained from regex capturing groups and/or add substrings in conditional replacements with the re.sub() function on a string

import regex, datetime input_text = "Alrededor de las 00:16 am del 2022_-_02_-_11 , quizas cerca de las 23:16 pm 2022_-_01_-_15" #example 1 input_text = "Alrededor de las 2022_-_02_-_18 00:16 am , quizas cerca de las 2022_-_12_-_01 a las 23:16 pm"…
Matt095
  • 857
  • 3
  • 9
0
votes
0 answers

regex patter not working after combing flags verbose and multili

import re st = """interface GigabitEthernet0/0 ip address 192.168.1.11 255.255.255.0 duplex auto speed auto media-type rj45 ! interface GigabitEthernet0/1 no ip address duplex auto speed auto media-type rj45 ! interface…
ver_roh
  • 15
  • 3
0
votes
0 answers

how to create elasticsearch tokens for a unique use case for text value?

I have a use case where i want to tokenise emailId with Category 1 words separated by punctuations & prefix tokens Category 2 words separated by punctuations & prefix tokens & along with punctuation for example. email - ona.ki@gl.co I want to know…
0
votes
0 answers

Find strings in a log file for zabbix monitoring

I need to find strings in a log file with regex and later send output to Zabbix monitoring server to fire triggers if needed. For example here is a part of the log file: ===== Backup Failures ===== Description: Checks number of studies that their…
Peter
  • 13
  • 2
0
votes
1 answer

How do I write a regex to match the pattern "Day Month Date TimeStamp Year"?

I want to filter log data using python regex based on the format "Day Month Date Timestamp Year" Example : Mon Mar 16 13:03:07 2020 Content of log file will look something like below SR 194 1584363914 0 1 Mon Mar 16 13:05:14 2020 200002305…
0
votes
1 answer

I am trying to compare 2 sets of matched groups in regex python

The files are the exact same, I'm applying regex to string input on copies of 2 exact same file, but i am not sure how to do the comparison of the groups. Here is my code: for res1 in result1: for res2 in result2: res2 =…
hfak
  • 15
  • 4
0
votes
1 answer

Capturing 0-n occurrences of a regex group

I'm parsing output from textfiles that could change depending on when script is executed. I want to capture one or more lines of ip address, advertised address, and age. When I run my script it only captures the first or last match depending on…
hfak
  • 15
  • 4