Question: i want to replace string from a file.
i have a line like this:

```
qwe{data:"dede-dddd-ssss",login:"user",display:"screen"},abc,xyz

```

i want to replace all string starting from data to login with spaces

i try this i can only replace the string, is there a way to replace with a starting and endpoint for string?

```
def source = new File("c:\\sq\\file1.txt") 
def dest = new File("c:\\sq\\file2.txt") 

def fileText = source.text
def filedest = dest.text
for ( index in 1..9 ) {
    fileText = (fileText =~ /data/).replaceFirst("")

```

Answer: 
This code has an anchored version (to `{`) of the regex:

```
def fileText = '''\
qwe{data:"dede-dddd-ssss",login:"user",display:"screen1"},abc,xyz
...
qwe{data:"data2",login:"user2",display:"screen2"},abc,xyz
...
qwe{data:"data3",login:"user3",display:"screen3"},abc,xyz\
'''

fileText = fileText.replaceAll(/(?<=\{)\s*data:[^,]+,\s*login:[^,]+,/ , '')
println fileText

```

Output:

```
qwe{display:"screen1"},abc,xyz
...
qwe{display:"screen2"},abc,xyz
...
qwe{display:"screen3"},abc,xyz

```

Try also in the [online groovy web console](https://groovyconsole.appspot.com/script/5177290749116416)

**UPDATE** 

If a understand correctly your request: this following code read the input text from `source` (`c:\\sq\\file1.txt`) and put the modified text into destination file `dest` (`c:\\sq\\file2.txt`):

```
def source = new File("c:\\sq\\file1.txt") 
def dest = new File("c:\\sq\\file2.txt") 

dest.write(source.text
  .replaceAll(/(?<=\{)\s*data:[^,]+,\s*login:[^,]+,/ , '') )

```
I'm not entirely clear on what your desired outcome is. If you want to remove the "data" and "login" fields and the corresponding values from the input strings, such that your example of:
`qwe{data:"dede-dddd-ssss",login:"user",display:"screen"},abc,xyz`
becomes:
`qwe{display:"screen"},abc,xyz` then you can easily use a regex to do this.

The following code:

```
​String str = """qwe{data:"dede-dddd-ssss",login:"user",display:"screen"},abc,xyz"​​""
str = str.replaceFirst("​​​​​​​​​​​​​data.*login:\".+?\",", '')
println str​

```

Prints `qwe{display:"screen"},abc,xyz`