DL1231 commented on code in PR #20865:
URL: https://github.com/apache/kafka/pull/20865#discussion_r2520505690


##########
tools/src/main/java/org/apache/kafka/tools/TopicCommand.java:
##########
@@ -751,8 +751,7 @@ public TopicCommandOptions(String[] args) {
                     KAFKA_CONFIGS_CLI_SUPPORTS_ALTERING_TOPIC_CONFIGS);
             describeOpt = parser.accepts("describe", "List details for the 
given topics.");
             topicOpt = parser.accepts("topic", "The topic to create, alter, 
describe or delete. It also accepts a regular " +
-                            "expression, except for --create option. Put topic 
name in double quotes and use the '\\' prefix " +
-                            "to escape regular expression symbols; e.g. 
\"test\\.topic\".")
+                            "expression, except for --create option. Put topic 
name in double quotes; e.g. \"test.*\".")

Review Comment:
   When there is no backslash, double quotes are required, see following 
example: 
   ```
   [root@test bin]# sh kafka-topics.sh --bootstrap-server 192.168.111.50:9092 
--describe --topic "^topic-\d+$"
   Topic: topic-11      TopicId: DQJaLhH2Sn-RONhUVtio7Q PartitionCount: 3       
ReplicationFactor: 3    
        Topic: topic-11 Partition: 0    Leader: 0       Replicas: 0,1,2 Isr: 
0,1,2
        Topic: topic-11 Partition: 1    Leader: 1       Replicas: 1,2,0 Isr: 
1,2,0
        Topic: topic-11 Partition: 2    Leader: 2       Replicas: 2,0,1 Isr: 
2,0,1
   Topic: topic-187863026       TopicId: mTgY2xuRQ5qXmLam67aZnA PartitionCount: 
3       ReplicationFactor: 3    
        Topic: topic-187863026  Partition: 0    Leader: 1       Replicas: 1,2,0 
Isr: 1,2,0
        Topic: topic-187863026  Partition: 1    Leader: 2       Replicas: 2,0,1 
Isr: 2,0,1
        Topic: topic-187863026  Partition: 2    Leader: 0       Replicas: 0,1,2 
Isr: 0,1,2
   [root@test bin]# sh kafka-topics.sh --bootstrap-server 192.168.111.50:9092 
--describe --topic "^topic-\\d+$"
   Topic: topic-11      TopicId: DQJaLhH2Sn-RONhUVtio7Q PartitionCount: 3       
ReplicationFactor: 3
        Topic: topic-11 Partition: 0    Leader: 0       Replicas: 0,1,2 Isr: 
0,1,2
        Topic: topic-11 Partition: 1    Leader: 1       Replicas: 1,2,0 Isr: 
1,2,0
        Topic: topic-11 Partition: 2    Leader: 2       Replicas: 2,0,1 Isr: 
2,0,1
   Topic: topic-187863026       TopicId: mTgY2xuRQ5qXmLam67aZnA PartitionCount: 
3       ReplicationFactor: 3    
        Topic: topic-187863026  Partition: 0    Leader: 1       Replicas: 1,2,0 
Isr: 1,2,0
        Topic: topic-187863026  Partition: 1    Leader: 2       Replicas: 2,0,1 
Isr: 2,0,1
        Topic: topic-187863026  Partition: 2    Leader: 0       Replicas: 0,1,2 
Isr: 0,1,2
   [root@test bin]# sh kafka-topics.sh --bootstrap-server 192.168.111.50:9092 
--describe --topic ^topic-\d+$
   Error while executing topic command : Topic '^topic-d+$' does not exist as 
expected
   [2025-11-13 08:34:18,254] ERROR java.lang.IllegalArgumentException: Topic 
'^topic-d+$' does not exist as expected
        at 
kafka.admin.TopicCommand$.kafka$admin$TopicCommand$$ensureTopicExists(TopicCommand.scala:402)
        at 
kafka.admin.TopicCommand$TopicService.describeTopic(TopicCommand.scala:314)
        at kafka.admin.TopicCommand$.main(TopicCommand.scala:62)
        at kafka.admin.TopicCommand.main(TopicCommand.scala)
    (kafka.admin.TopicCommand$)
   [root@test bin]# sh kafka-topics.sh --bootstrap-server 192.168.111.50:9092 
--describe --topic ^topic-\\d+$
   Topic: topic-11      TopicId: DQJaLhH2Sn-RONhUVtio7Q PartitionCount: 3       
ReplicationFactor: 3    
        Topic: topic-11 Partition: 0    Leader: 0       Replicas: 0,1,2 Isr: 
0,1,2
        Topic: topic-11 Partition: 1    Leader: 1       Replicas: 1,2,0 Isr: 
1,2,0
        Topic: topic-11 Partition: 2    Leader: 2       Replicas: 2,0,1 Isr: 
2,0,1
   Topic: topic-187863026       TopicId: mTgY2xuRQ5qXmLam67aZnA PartitionCount: 
3       ReplicationFactor: 3    
        Topic: topic-187863026  Partition: 0    Leader: 1       Replicas: 1,2,0 
Isr: 1,2,0
        Topic: topic-187863026  Partition: 1    Leader: 2       Replicas: 2,0,1 
Isr: 2,0,1
        Topic: topic-187863026  Partition: 2    Leader: 0       Replicas: 0,1,2 
Isr: 0,1,2
   
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to