0

I have made a clumsy first attempt at fuzzy pattern matching using the re module in python 2.7.

Unfortunately every attempt I make returns an empty list. I simply don't understand the syntax required. I was wondering if someone might tell me why the following code:

import re
m = re.findall('(ATCT){e<=1}', 'ATCGATCGGCATGCAGTGCAGAAGTGACGAT')
print m

returns an empty list?

9
  • What's ur expected output? Commented Feb 17, 2016 at 11:28
  • Are you only interested in the explanation? Not in a solution? Your regex is a mess. It matches ATCT followed with {e<=1} - these are literal character sequences. See what it matches. Commented Feb 17, 2016 at 11:28
  • @AvinashRaj the pattern should match to several places in the string with one match, the output should be a list of those patterns. Commented Feb 17, 2016 at 11:29
  • @WiktorStribiżew I am interested in both. Commented Feb 17, 2016 at 11:30
  • If you are interested in a solution, please explain - illustrate - what you need to obtain. Commented Feb 17, 2016 at 11:31

1 Answer 1

2

Since you intended to use the PyPi regex module, you need to use

>>> import regex
>>> m = regex.findall('(ATCT){e<=1}', 'ATCGATCGGCATGCAGTGCAGAAGTGACGAT')
>>> print(m)
['ATCG', 'ATCG']
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. I did not realise they were different modules as I was unaware of the difference. As a follow up question, is there a way to perform this using the re module?
There is no way to do that with the re module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.