Python Forum
Regular expressions help re.error: multiple repeat at position 23
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regular expressions help re.error: multiple repeat at position 23
#3
If they did not teach to name variables in English...

Variable names are part of function documentation, helping your reader to understand the code. Portuguese - you are discouraging your potential helpers from the international community.

Also, your code is too crowded, make it still less readable - see PEP-8 for guidance. And don't show the full code - show just places that don't work (again, helps your potential helpers to concentrate on your problem - and not on long strings most won't be able to read)

Still:
  • Use this site to practice RE and RT(F)M for guidance. Try to figure out the common pattern - that is the purpose of RE, not endless if/elif/else chain
  • re.match searches from the beginning of the string; ^ symbol is redundant.
  • {1} is a redundant and stupid quantity modifier; it actually says "this string (sub-RE) will appear once"; if some string(sub-RE) shows within RE without quantity modifier - it means that you expect it to show once
    E.g, TCAGR{1} means that you expect string TCAG, followed by one R (actually, string comparison will do). You crowd your RE with meaningless modifiers, making them still harder to read

Couple of generic pointers:
  • pedido[3]==1 or pedido[3]==2 or pedido[3]==4 or pedido[3]==5
    may be rewritten (take your pick)
    pedido[3] in [1, 2, 3, 4, 5]
    1 <= pedido[3] <= 5
    pedido[3] in range(1, 6)
  • Most of your choice function are candidates for dict
  • int(pedido[3]) == 1 or pedido[3] == '1'?
  • Indents - well, you were already told
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Messages In This Thread
RE: Regular expressions help re.error: multiple repeat at position 23 - by volcano63 - Sep-18-2018, 01:29 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Search in a file using regular expressions ADELE80 2 683 Dec-18-2024, 12:29 PM
Last Post: ADELE80
  Use or raw string on regular expressions Zaya_pool 5 1,644 May-09-2024, 06:10 PM
Last Post: Zaya_pool
Information Do regular expressions still need raw strings? bobmon 3 2,415 May-03-2024, 09:05 AM
Last Post: rishika24
  Recursive regular expressions in Python risu252 2 4,958 Jul-25-2023, 12:59 PM
Last Post: risu252
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 2,853 May-22-2023, 10:39 PM
Last Post: ICanIBB
Sad Regular Expressions - so close yet so far bigpapa 5 2,154 May-03-2023, 08:18 AM
Last Post: bowlofred
  Repeat request by else stsxbel 2 1,973 Jul-30-2022, 03:34 PM
Last Post: stsxbel
  How to move multiple columns to initial position SriRajesh 4 2,593 Jul-02-2022, 10:34 AM
Last Post: deanhystad
  List Creation and Position of Continue Statement In Regular Expression Code new_coder_231013 3 2,599 Jun-15-2022, 12:00 PM
Last Post: new_coder_231013
  get out of while loop and stop repeat Frankduc 11 5,206 Apr-26-2022, 10:09 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020