Regex help required

前端 未结 3 1240
天命终不由人
天命终不由人 2021-01-24 02:38

I am trying to replace two or more occurences of
(like


) tags together with two

3条回答
  •  情话喂你
    2021-01-24 03:08

    Here's some Groovy code to test your Pattern:

    import java.util.regex.*
    
    Pattern brTagPattern = Pattern.compile( "(<\\s*br\\s*/\\s*>\\s*){2,}", Pattern.CASE_INSENSITIVE | Pattern.DOTALL )
    def testData = [
      ['',                            ''],
      ['
    ', '
    '], ['< br/>
    ', '

    '], ['


    ', '

    '], ['
    < br/ >
    ', '

    '], ['


    ', '

    '], ['




    ', '

    '], ['


    w
    ','

    w
    '], ] testData.each { inputStr, expected -> Matcher matcher = brTagPattern.matcher( inputStr ) assert expected == matcher.replaceAll( '

    ' ) }

    And everything seems to pass fine...

提交回复
热议问题