1

How do I replace all the characters with nothing (thus deleting them) up to a certain character? I have a log string which is an XML request:

I have a string like this:

   Mon Dec 19 09:50:50 EST 2016:INFO:
    string = "test-testing ID:idm-zx-sawe.3CE65834D32AD741:370  <?xml version="1.0" encoding="UTF-8"?>"

   string.replaceAll("([^,]*'&lt;')", "").replaceAll("(?m)^\\s*ID.*","");

I need to remove all the charters before <?xml

and return the following string: "test-testing ID:idm-zx-sawe.3CE65834D32AD741:370

I'm trying with this regular expression:

 /.*<\?/ - need this translated to groovy string.replaceAll(".*<\?","")
Stedy
  • 7,359
  • 14
  • 57
  • 77
  • Can you please provide the details about what exact your use case? that would help to read the problem in better way. What are you trying to do? what type of steps in your test case? – Rao Dec 19 '16 at 02:42
  • Possible duplicate of [Regex: matching up to the first occurrence of a character](http://stackoverflow.com/questions/2013124/regex-matching-up-to-the-first-occurrence-of-a-character) – Northys Dec 19 '16 at 02:50
  • i capture a log file and store the contents in a string. the log file contains a request file . in the beginning of the request file there is different logging deepening on the system,. i need to remove this login and only have a clean request file. – user7083100 Dec 19 '16 at 03:09
  • i capture a log file and store the contents in a string. the log file contains a request file . in the beginning of the request file there is different logging deepening on the system,. i need to remove this login and only have a clean request file. i check the link above northys, close but not right. i need to find the charter. im able to do this in regular expression with the following. /.*<\?/ - need this translated to groovy replaceAll (".*<\?","") – user7083100 Dec 19 '16 at 03:10

1 Answers1

0

I would do it like this:

​def string = 'test-testing ID:idm-zx-sawe.3CE65834D32AD741:370  <?xml version="1.0" encoding="UTF-8"?>'
def start = ​​​​​​​​​​​​​​​​string.indexOf('<?xml')​​​​​;
if (start) {
    string = string.substring(start);
}​

string is:

<?xml version="1.0" encoding="UTF-8"?>
Fels
  • 1,214
  • 2
  • 13
  • 27