capture « regex « Python Data Type Q&A

Home
Python Data Type Q&A
1.array
2.date
3.dictionary
4.Format
5.integer
6.List
7.numpy
8.regex
9.string
10.tuple
Python Data Type Q&A » regex » capture 

1. Find out number of capture groups in Python regular expressions    stackoverflow.com

Is there a way to determine how many capture groups there are in a given regular expression? I would like to be able to do the follwing:

def groups(regexp, s):
    ...

2. Python regular expressions - how to capture multiple groups from a wildcard expression?    stackoverflow.com

I have a Python regular expression that contains a group which can occur zero or many times - but when I retrieve the list of groups afterwards, only the last one ...

3. How do you substitue a Python capture followed by a number character?    stackoverflow.com

When using re.sub, how to you handle a situation where you need a capture followed by a number in the replacement string? For example, you cannot use "\10" for ...

4. How do capture groups work? (wrt python regular expressions)    stackoverflow.com

While using regex to help solve a problem in the Python Challenge, I came across some behaviour that confused me. from here: (...) Matches whatever regular expression is inside ...

5. What regex can I use to capture groups from this string?    stackoverflow.com

Assume the following strings:

  • A01B100
  • A01.B100
  • A01
  • A01............................B100 ( whatever between A and B )
The thing is, the numbers should be \d+, and in all of the strings A will always be present, while B ...

6. Why regular expression's "non-capturing" group is not working    stackoverflow.com

In my snippet below, the non-capturing group "(?:aaa)" should be ignored in matching result, so the result should be "_bbb" only.
However, I get "aaa_bbb" in matching result; only when I specify group(2) ...

7. Capture the last occurrence of a tag    stackoverflow.com

My text is of the form:

<Story>
 <Sentence id="1"> some text </Sentence>   
 <Sentence id="2"> some text </Sentence>   
 <Sentence id="3"> some text </Sentence>   
My task ...

8. Python regex non-capturing issue?    stackoverflow.com

I was trying to get all quoted (" or ') substrings from a string excluding the quotation marks. I came up with this:

"((?:').*[^'](?:'))|((?:\").*[^\"](?:\"))"
For some reason the matching string still contains the quotation ...

9. Searching and capturing a character using regular expressions Python    stackoverflow.com

While going through one of the problems in Python Challenge, I am trying to solve it as follows: Read the input in a text file with characters as follows:

DQheAbsaMLjTmAOKmNsLziVMenFxQdATQIjItwtyCHyeMwQTNxbbLXWZnGmDqHhXnLHfEyvzxMhSXzd
BEBaxeaPgQPttvqRvxHPEOUtIsttPDeeuGFgmDkKQcEYjuSuiGROGfYpzkQgvcCDBKrcYwHFlvPzDMEk
MyuPxvGtgSvWgrybKOnbEGhqHUXHhnyjFwSfTfaiWtAOMBZEScsOSumwPssjCPlLbLsPIGffDLpZzMKz
jarrjufhgxdrzywWosrblPRasvRUpZLaUbtDHGZQtvZOvHeVSTBHpitDllUljVvWrwvhpnVzeWVYhMPs
kMVcdeHzFZxTWocGvaKhhcnozRSbWsIEhpeNfJaRjLwWCvKfTLhuVsJczIYFPCyrOJxOPkXhVuCqCUgE
luwLBCmqPwDvUPuBRrJZhfEXHXSBvljqJVVfEGRUWRSHPeKUJCpMpIsrV.......
What I ...

10. Regex to capture the codes between specific function    stackoverflow.com

I have been experimenting with python re, trying to capture specific variables between specific functions. To illustrate let me give an example of file contents of a php file :-

public function ...

11. Regular expression group capture with multiple matches    stackoverflow.com

Quick regular expression question.
I'm trying to capture multiple instances of a capture group in python (don't think it's python specific), but the subsequent captures seems to overwrite the previous. In ...

12. Capturing groups and lookarounds    stackoverflow.com

I want to know how capturing groups (or non capturing) are affecting lookarounds in Regex. Here are 2 example:

test (?:(?!<start).)+

test (?!<start).+
I would appreciate if anybody can explain how regex engine is interpreting ...

13. How to capture all characters in binary string without python interpreting it    stackoverflow.com

Here is how I reproduce the problem: Create a log file called 'temp.log' and paste this line into it

DEBUG: packetReceived '\x61\x62\x63'
I want to have a script which will read the line from ...

14. python regex repetition with capture question    stackoverflow.com

using python3's regex capabilities, is it possible to capture variable numbers of capture blocks, based on the number of the repetitions found? for instance, in the following search strings, i ...

15. How to match--but not capture--in Python regular expressions?    stackoverflow.com

I've got a function spitting out "Washington D.C., DC, USA" as output. I need to capture "Washington, DC" for reasons that have to do with how I handle every single other ...

16. Python Regex Capture Only Certain Text    stackoverflow.com

I am trying to find functionality in python similar to the Ruby function scan. My goal is to grab all the text in-between two curly braces in a list. If there ...

17. How can I capture this through a regex?    stackoverflow.com

I have some text like this:

ABCPQR01 is not at all good
EFHSTU39 is somewhat nicer
and I want to capture the ABC... and EFH... type words. The first set of three letters can ...

18. Unable to get regex to capture last group    stackoverflow.com

I'm trying to write a regex in python to parse a Newick tree, but for the life of me I can't get the last part of it to match. There are ...

19. Python: handling capturing groups in re.sub?    stackoverflow.com

Very beginner question about capturing groups (sorry) but hard to find the answer using Google, or figure out alone from regex websites. I want to take the string 0.71331, 52.25378 and ...

21. Capturing shortest string with RegEX    python-forum.org

22. capturing regex matches    python-forum.org

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.