0

I am trying to extract values "app_name" and "This is a great app" from the following but do not know how I can do that. I am not able to figure out the regular expression for this.

This is what my input looks like:

<string name = "app_name"> This is a great app </string>

This is not an effort to read values from Strings.xml on to Java code in Android. This is a totally different case, I just want to print out the values.

4
  • is it in your projects Strings.xml resource file? If so you don't need to use regex to pull out the value of it. Commented Apr 20, 2012 at 21:14
  • 1
    and this looks like xml to me... even if it's not in your Strings.xml file, you don't need regex Commented Apr 20, 2012 at 21:17
  • @Tim,@jadk I am not trying to refer this in Android app, this is totally different case. Commented Apr 20, 2012 at 21:30
  • @Randon P Then why did you tag your question with [android]? =O Commented Apr 20, 2012 at 21:36

1 Answer 1

1
/<string name="([^"]+)">([^<]+)<\/string>/i

The name attribute (app_name) will be stored in back-reference 1, and the actual string value (This is a great app) will be stored in back-reference 2.

With more information, this regexp can be modified to work in a greater variety of situations, but with the limited information given, it will work, but may not work in all cases.

Sign up to request clarification or add additional context in comments.

2 Comments

Can you show it in code, I am not able to identify the functions to be used for parameter /<string name="([^"]+)">([^<]+)<\/string>/i . Thanks.
As I'm not a Java nor Android programmer, I don't know the functions or relevant code that you would need to use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.