• Home
  • Django
  • get variable value from regular expression

get variable value from regular expression

linkaiyi
Follow

get variable value from regular expression

>>> m = re.match(r"(?P<first_name>\w+) (?P<last_name>\w+)", "Malcom Reynolds")
>>> m.groupdict()
{'first_name': 'Malcom', 'last_name': 'Reynolds'}

>>> import re
>>> p = re.compile("lalala(I want this part)lalala")
>>> p.match("lalalaI want this partlalala").group(1)
'I want this part'

get non digit

You want [\D] or [^\d], but not [^\D]. Regex is case-sensitive, \d matches a digit, and \D matches anything but a digit.

Object has 0 attachments

Was this article helpful?

This article is viewed 37 times!

Recent Viewed Articles

0 Comments

Leave a Comment

Support