简体   繁体   中英

How to extract group pattern from re pattern?

I have simple python code:

import re


regex=re.compile('some_regex(regex_in_first_group)other_regex')

Is there a way of extracting from such regular expression only expression that is in first group?

so in this situation I would like to obtain:

group_regex='regex_in_first_group'

Yes - use match objects. See https://docs.python.org/3.8/library/re.html#match-objects and especially the description of Match.group() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM