Tolgar
asked on
How to remove part of a string from another string by keeping some of it conditionally in Java?
I have string and I modify this string using the code below:
The input is:
The code that I use is:
The output is this:
Now, I would like to change this regexp in such a way that the output will be like this for the same input:
Expected output:
As you can see, the difference between the previous output and this one is the -d flag in the front. The idea is to keep the -d flag if there is any and do the rest same.
The input data is in one big string. I would prefer to do it in one regexp instead of looping through the lines.
How can I do?
Thanks,
The input is:
-f S:\some\keyword\path\to\a\file.c
-d C:some\other\path\to\keyword\another\file.cpp
The code that I use is:
content = content.replaceAll("(?m)^.*?(?=keyword)", "")
The output is this:
keyword\path\to\a\file.c
keyword\another\file.cpp
Now, I would like to change this regexp in such a way that the output will be like this for the same input:
Expected output:
keyword\path\to\a\file.c
-d keyword\another\file.cpp
As you can see, the difference between the previous output and this one is the -d flag in the front. The idea is to keep the -d flag if there is any and do the rest same.
The input data is in one big string. I would prefer to do it in one regexp instead of looping through the lines.
How can I do?
Thanks,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER