regex - Replacing just the match of regular expression in Eclipse find and replace -


so have ton of files need changed. this

string example=/abc/def/pattern/ghi 

and want change pattern else, let's fix

what is:

string example=/abc/def/fix/ghi 

what i'm getting is:

fix (the whole line gets changed, want match changed)

this regular expression i'm using, trying avoid commented lines

^(?!\s*(//|\*)).*/pattern/

you may wrap part of pattern need keep after replacement capturing parentheses , use backreference in replacement string:

search for: ^(?!\s*(?://|\*))(.*/)pattern/
replace:    $1fix/

now, pattern matches:

  • ^ - start of line
  • (?!\s*(?://|\*)) - if not followed 0+ whitespaces , // or * (note non-capturing grop (?:...) used simplify backreference usage)
  • (.*/) - group 1 capturing 0+ chars other linebreak symbols last /
  • pattern/ - literal substring pattern/.

in replacement pattern, $1 re-inserts whole line start / before pattern/, , fix/ literal replacement part.

enter image description here


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -