简体   繁体   English

正则表达式 - 匹配重复模式

[英]Regex - Matching repeating pattern

I have the following string which contains a repeating pattern of text followed by parentheses with an ID number.我有以下字符串,其中包含重复的文本模式,后跟带有 ID 号的括号。

The New York Yankees (12980261666)\n\nRedsox (1901659429)\nMets (NYC) 
(21135721896)\nKansas City Royals (they are 7-1) (222497247812331)\n\n
other team  (618006)\n

I'm struggling to write a regex that would return:我正在努力编写一个会返回的正则表达式:

The New York Yankees (12980261666)

Redsox (1901659429)

Mets (NYC) (21135721896)

Kansas City Royals (they are 7-1) (222497247812331)

other team  (618006)

The newline character could be replaced later with a string.replace('/n', '') .以后可以用string.replace('/n', '')替换换行符。

use the negate character to achieve this.使用否定字符来实现这一点。

String pat="([^\\\\n])"字符串 pat="([^\\\\n])"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM