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: 
If you want it in the files, then you can try below, and find the updated data in test2.txt:

note:please update the file paths as per your environment

Courtesy @GsusRecovery for regex

```
def fileContent = new File('/tmp/test.txt').text
def replacedContent = fileContent.replaceAll(/(?<=\{)\s*data:[^,]+,\s*login:[^,]+,/ , '')
def newFile = new File('/tmp/test2.txt')
newFile.write(replacedContent)

```
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`