Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-6562

Regex argument is altered when passed to Groovy program on Windows

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.2.1
    • None
    • None
    • Windows 7

    Description

      Caret (^) is removed from regex argument when passed to a Groovy program from Windows command line, thus altering the meaning of the pattern altogether. An identical Java program receives the argument as-is, this proving that the problem isn't with Windows cmd. Details here:
      http://groovy.329449.n5.nabble.com/Groovy-alters-my-regex-argument-td5718306.html

      class RegexG {
          static void main(String[] args) {
      		println "Pattern: ${args[0]}"
      		println "String: ${args[1]}"
      		
              Pattern p = Pattern.compile(args[0])
              Matcher m = p.matcher(args[1])
      
      	while (m.find()) {
      	    println("Group: \"${m.group()}\"")
      	}
      	m.reset()
      
      	while (m.find()) {
      	    println("Replace all: \"${m.replaceAll('')}\"")
      	}
          }
      }
      

      Input

      >groovy RegexG "[^a-zA-Z0-9\\\\s]" "a-b; 9"

      Output (notice the ^ stripped out)

      Pattern: [a-zA-Z0-9\\s]
      String: a-b; 9
      Group: "a"
      Group: "b"
      Group: "9"
      Replace all: "-; "

      Attachments

        Activity

          People

            Unassigned Unassigned
            asarkar Amardeep Sarkar
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: