I get two configure strings:
- jdbc:mysql://127.0.0.1:3306/DataBaseName
- jdbc:mysql://127.0.0.1:3306/DataBaseName?encoding=utf8
I want to extract the DataBaseName field from them, so I used code bellow to match that field:
match = re.search(r'(?<=/)(\w+)(?=[\?$])', config_str)
if match is not None and len(match.groups()) > 0:
print match.groups()[1]
But it did not work.
I tried and confirmed that:
(?<=/)(\w+)(?=$)
matchesjdbc:mysql://127.0.0.1:3306/DataBaseName
(?<=/)(\w+)(?=\?)
matchesjdbc:mysql://127.0.0.1:3306/DataBaseName?encoding=utf8
So I think the reason is special character does not work in square bracket.
Does this true? And how can I make my code work?