cdalsanto
cdalsanto

Reputation: 13

Android Structural Find & Replace XML

I'm trying to find instances in my resources where View contains background="@+id/play_bubble" and replace the View with custom view Bubble.

So the current View looks like this:

<View
    android:id="@+id/obstacle3"
    android:layout_height="@dimen/obstacle_width"
    android:layout_width="@dimen/obstacle_width"
    android:background="@drawable/play_bubble"
    android:layout_alignParentLeft="true"
    android:layout_above="@id/obstacle2" />

I want it to find all View objects that contain a certain background, regardless of the other attributes. I'm not getting any results though.

My end result after replace should look like this:

<Bubble
    android:id="@+id/obstacle3"
    android:layout_height="@dimen/obstacle_width"
    android:layout_width="@dimen/obstacle_width"
    android:background="@drawable/play_bubble"
    android:layout_alignParentLeft="true"
    android:layout_above="@id/obstacle2" />

Any help is much appreciated.

Edit:

So here's the interface I'm dealing with. I'm not familiar with regex at all, so I'm not sure if I'm inputting things correctly, but it's not returning any results. Find/Replace

Upvotes: 1

Views: 133

Answers (1)

user557597
user557597

Reputation:

Since you mention simple find/replace, this regex should do it.

Find: <View(\s+[^>]*?)background="@\+id/play_bubble"([^>]*?/>)
Replace: <Bubble$1background="something_new"$2

Formatted:

 <View
 (                                  # (1 start)
      \s+ 
      [^>]*? 
 )                                  # (1 end)
 background="@\+id/play_bubble"
 (                                  # (2 start)
      [^>]*? 
      />
 )                                  # (2 end)

Upvotes: 2

Related Questions