lilzz
Posts: 411
Joined: Sat Nov 30, 2013 5:27 pm

The following regular expression

Fri Oct 30, 2015 12:37 am

1) match = re.match(r"B(\d+)\[(\d+)\]$", bit)

what does "B(\d+)\[(\d+)\]$" means?

2) match = re.match(r"(.*?_)(\d+)(.*)", s[2])

"(.*?_)(\d+)(.*)"?

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: The following regular expression

Fri Oct 30, 2015 1:58 am

Google still broken for you?

Knock yourself out:
http://www.zytrax.com/tech/web/regex.htm

SonOfAMotherlessGoat
Posts: 690
Joined: Tue Jun 16, 2015 6:01 am

Re: The following regular expression

Fri Oct 30, 2015 3:41 am

/B(\d+)\[(\d+)\]$/
B matches the character B literally (case sensitive)
1st Capturing group (\d+)
\d+ match a digit [0-9]
Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
\[ matches the character [ literally
2nd Capturing group (\d+)
\d+ match a digit [0-9]
Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
\] matches the character ] literally
$ assert position at end of the string
MATCH INFORMATION

https://regex101.com/
Account Inactive

User avatar
DougieLawson
Posts: 39124
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: The following regular expression

Fri Oct 30, 2015 10:31 am

Grab a copy of http://www.weitz.de/regex-coach/ and install it on your Windows system. That lets you disassemble regexes and step through a regex versus a target string showing the matches as you go.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Return to “Python”