I want to match:
!argument1 [argument2], where argument2 is optional. I have it figured out using a second optional group, but I can't get it to ignore the space between the arguments.
regex="!([a-z]) ?\W(.)"
Matches: "!test case"
"!test "
Not matching: "!test"
I tried to throw in an '?(: )' in the regex to make a non capturing optional group containing the space but to no avail, resulting in the following: regex="!([a-z])?(: )?\W(.)"
The result is 'raise error, v # invalid expression'
some tries usin the python shell:
>>> regex="!([a-z]*) ?\W(.*)"
>>> data="!hello dear"
>>> re.search(regex, data).groups()
('hello', 'dear')
>>> data="!hello "
>>> re.search(regex, data).groups()
('hello', '')
>>> data="!hello"
>>> re.search(regex, data).groups()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'groups'
!([a-z]+)