Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
matching a repeating string
#1
i have a single character (such as ".") in variable foo and another variable bar with a one or more repeat of a single character (such as "..."). i would like to know if foo matches all the repeats of bar. empty strings should never be considered to match. is this the best way to do that?
    if foo and bar and foo*len(bar) == bar:
        ...
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Ifbarwill always be a single character repeated an number of times thenif foo in bar :would be the most straight forward test to see ifbarisfoorepeated.
Reply
#3
no, bar could be some other value that may or may not be a repeating character. it may have an instance of foo within but if there is anything else in bar then i want a false result. bar="BashBedlam" and foo="B" needs to be false, but bar="BB" needs to be true when foo="B".
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Matching string from a file tester_V 5 454 Mar-05-2024, 05:46 AM
Last Post: Danishhafeez
  Why is 2/3 not just .666 repeating? DocFro 4 709 Dec-12-2023, 09:09 AM
Last Post: buran
  repeating a user_input astral_travel 17 2,311 Oct-26-2022, 04:15 PM
Last Post: astral_travel
  if else repeating Frankduc 12 2,517 Jul-14-2022, 12:40 PM
Last Post: Frankduc
  Matching multiple parts in string fozz 31 6,351 Jun-13-2022, 09:38 AM
Last Post: fozz
  Matching Exact String(s) Extra 4 1,933 Jan-12-2022, 04:06 PM
Last Post: Extra
  Random Number Repeating Tzenesh 5 4,052 Jan-13-2021, 10:00 PM
Last Post: deanhystad
  factorial, repeating Aldiyar 4 2,815 Sep-01-2020, 05:22 PM
Last Post: DPaul
  number repeating twice in loop JonnyEnglish 3 3,320 Nov-24-2019, 09:23 AM
Last Post: ThomasL
  Repeating equations Tbot100 2 3,281 May-29-2019, 02:38 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

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