Mohamad Shaker
Mohamad Shaker

Reputation: 1486

How to split string using regular expression in java

I have a string contains multi language text as follow

{|en|}Audio Albums{|/en|}{|ar|}الألبومات الصوتية{|/ar|}

I need a function to get the text of specific language

getText("en") should returns Audio Albums

I think I have to use regular expression.

Upvotes: 0

Views: 61

Answers (1)

Zbynek Vyskovsky - kvr000
Zbynek Vyskovsky - kvr000

Reputation: 18825

This should work:

Pattern pattern = Pattern.compile("\{\|"+lang+"\\|\\}(.*)\\{\\|/"+lang+"\|\}");
Matcher matcher = pattern.matcher(content);
return matcher.find() ? matcher.group(1) : null;

Upvotes: 1

Related Questions