In “aa67bc54c9”, is there any way to print “aa” 67 times, “bc” 54 times and so on, using regular expressions?

前端 未结 5 2093
谎友^
谎友^ 2020-12-15 14:13

I was asked this question in an interview for an internship, and the first solution I suggested was to try and use a regular expression (I usually am a little stumped in int

5条回答
  •  忘掉有多难
    2020-12-15 14:23

    Answering your question directly:

    • No, regular expressions match text and don't print anything, so there is no way to do it solely using regular expressions.

    The regular expression you gave will match one string/number pair; you can then print that repeatedly using an appropriate mechanism. The Perl solution from @tster is about as compact as it gets. (It doesn't use the names that you applied in your regex; I'm pretty sure that doesn't matter.)

    The remaining details depend on your implementation language.

提交回复
热议问题