I need to make regular expression which will match string starts with '->' or '<-' and after that continue with some symbols. For example string '-> arrow 43' should be matched. I don't have much experience in working with re module so it's RegExpression I made '(<\-|\->).+'
. But when I run print(re.findall('(<\-|\->).+', '-> arrow 43'))
It prints me that ['->']
Why? Shouldn't it prints the whole string? Maybe I have got mistakes in a pattern?
Asked
Active
Viewed 19 times
0
![](../../users/profiles/10371918.webp)
cooleck
- 74
- 1
- 2
- 10
-
1Try `re.fullmatch()` instead. Python's `re` module interprets parentheses as a *group*, and `findall()` returns only the things inside groups. – Green Cloak Guy Jun 18 '19 at 20:03
-
Use non-capturing groups instead of capturing, `re.findall('(?:).+', '-> arrow 43')` – Wiktor Stribiżew Jun 18 '19 at 20:04