I am trying to change the path delimiter from windows to linux-style, but only in specific code lines. To find the specific lines is no problem, but I wand to automate the replacing.
IDE: eclipse
Every Path to change has a copy statement, for example:
copy "path\to\..\file.cpy"
.
Regex to search: (copy[\s]+")[(..|[\w]+)[\\]]+(.cpy")
Problem, I get only the start and end of a line: $1 is the copy " part, the $2 is the .cpy" part. I have no clue how to get the multiple folders.
You need this kind of pattern that uses the \G
feature that succeeds at the start of the string or at the position after the previous match:
pattern: ((?:\G(?!\A)|copy\s+")[^\\"]*)\\
replacement: $1/
details:
( # capture group 1
(?: # non capturing group with two possible starts
\G # contiguous to the previous match or the start of the string
(?!\A) # disallow the start of the string to match
| # OR
copy\s+" #"# first match
)
[^\\"]* #"# all that isn't a backslash or a double quote
)
\\ # the literal backslash
At the beginning (before the first match) the first branch fails (because of the \G
assertion), only the second branch can succeed. Once done, the first branch is able to succeed.
Once the last backslash is reached, the contiguity is broken (ie: the first branch can't succeed no more and the only way for the pattern to succeed is the second branch. etc.
Note: if you want to ensure that your path ends with the .cpy
extension, you need to add this condition with a lookahead assertion in the second branch:
((?:\G(?!\A)|copy\s+"(?=[^"]\.cpy"))[^\\"]*)\\