2

Hi i have to replace at least 100 instances of a string in a single code. The string i want to replace is

Music2.playGeneric2(context, R.raw.try_again);//text after R.raw.* could be anything

or Music2.playGeneric2(context, R.raw.tryagain);

with

Music2.playGeneric2(context, "try_again.mp3"); and Music2.playGeneric2(context, "tryagain.mp3");

I have found a lot for this but could not create a regular expression as i am new to it, hope to get some help....Thanx in advance

Ruchira Gayan Ranaweera
  • 34,993
  • 17
  • 75
  • 115
Sydroid
  • 509
  • 1
  • 8
  • 16

1 Answers1

1

look at this question: Is there a way to find/replace across an entire project in Eclipse?

search --> file you can use a regex to search and there's a replace option.

as for a regexp that would capture your methods, you could try:

Music2.playGeneric2\(context, R\.raw\.([^)]*)\)(.*)

that would set the 2nd argument (technically everything after the 1st argument up to the close-bracket as the 1st capture group, and the rest of the line as the 2nd capture group.

you could then replace with something like:

Music2.playGeneric2(context, "$1")$2

to quote the 2nd argument

Community
  • 1
  • 1
radai
  • 23,949
  • 10
  • 71
  • 115
  • I want to find and replace particular strings in a file...dont want to search a file.. – Sydroid Jan 13 '14 at 06:20
  • @Sydroid - it searches for text inside files. – radai Jan 13 '14 at 06:21
  • hey nice, now i want to replace "R.raw." to a"/""(double quotation mark) and "");" to ".mp3);" How should i do this – Sydroid Jan 13 '14 at 06:57
  • Hey its working Find : Music2.playGeneric2\(context, R\.raw\.([^)]*)\)(.*) Replace : Music2.playGeneric2(context, "$1.mp3")$2 but not for 2 underscore for eg: try_again_01 – Sydroid Jan 13 '14 at 08:17