K
K
Kirill Karpik2020-05-08 20:19:13
Parsing
Kirill Karpik, 2020-05-08 20:19:13

How to find a match so that the group is either before or before the word?

Skill parsing. There is a group of skills - /(python/java|c\+\+|c)/gmi (I'll shorten it, because this is just an example). An extreme case here is /c/ because this letter can simply be in a Latin word. It will be an independent word if either after or before it there are punctuation marks or spaces - /( |,|.|$|^)/gmi. It turns out that this group should be either before or after, but it can also be there and there, but it can never. Is there any good solution for this? I will be glad to any other similar or more effective solutions.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2020-05-08
@phaggi

You can try something like this:

spoiler
import re
data = '/(python/java|c\+\+|c)/gmi'

string = r'(\b[\w\\+]+)'
print(re.findall(string, data))

But they say that if you try to solve the problem through regexp, then you now have two problems...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question