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 1,046 Mar-05-2024, 05:46 AM
Last Post: Danishhafeez
  Why is 2/3 not just .666 repeating? DocFro 4 1,204 Dec-12-2023, 09:09 AM
Last Post: buran
  repeating a user_input astral_travel 17 3,440 Oct-26-2022, 04:15 PM
Last Post: astral_travel
  if else repeating Frankduc 12 3,521 Jul-14-2022, 12:40 PM
Last Post: Frankduc
  Matching multiple parts in string fozz 31 8,446 Jun-13-2022, 09:38 AM
Last Post: fozz
  Matching Exact String(s) Extra 4 2,391 Jan-12-2022, 04:06 PM
Last Post: Extra
  factorial, repeating Aldiyar 4 3,288 Sep-01-2020, 05:22 PM
Last Post: DPaul
  Repeating equations Tbot100 2 3,656 May-29-2019, 02:38 AM
Last Post: heiner55
  repeating for loop Kaldesyvon 5 4,419 Dec-06-2018, 08:00 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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