Question: I am given a = [13, 20, 7, 4] array of integers and I am trying to write a digitalsumandsort(a) = [20, 4, 13, 7] function as shown. If two numbers have the same sum of digits, the smaller one (in the regular sense) should come first. 4 and 13 have the same sum of digits, however 4 < 13 thus 4 comes before 13 in any digitalsumandsort sorting where both are present. But I can only sort the sum of the digits not the numbers. Hash function will be perfect for this problem but I am trying to solve this with just using array of integers. Here is my code and any suggestions would be greatly appreciated.

```
std::vector<int> digitalsumandsort(std::vector<int> a) {
    std::vector<int> result;
    int sum=0;
    int max=999;
    int temp;
    for (int i=0; i<a.size();i++){
        temp=a[i];
        while(temp>0){
            sum+=temp%10;
            temp/=10;
        }
        result.push_back(sum);
        sum=0;    
    }
    std::sort(result.begin(),result.begin()+4);
    return result;
}

```

Input:
a: [13, 20, 7, 4]
Output:
[2, 4, 4, 7]
Expected Output:
[20, 4, 13, 7]

Answer: 
You could use the expression `<[^>]*>` to match everything that was within a single pair of angled braces :

```
import java.util.regex.Matcher;
import java.util.regex.Pattern;

// Define your regex
Pattern regex = Pattern.compile("<[^>]*>");
// Get your matches
Matcher m = regex.matcher("{your-input-here}");
// Iterate through your matches
while(m.find()){
    // Output each match
    System.out.println(m.group(0));
}

```

You can [see a working example of this here](https://ideone.com/fork/8Vb9Ts).
The question as been well answered already, but another option is using `<.*?>`, i.e:

```
String text = "name of the person <emailoftheperson@someemail.com> name of another person <emailoftheanotherperson@someemail.com>";
Pattern regex = Pattern.compile("<.*?>");
Matcher regexMatcher = regex.matcher(text);
while (regexMatcher.find()) {
    System.out.println(regexMatcher.group(0));
}

```

---

**Demos:** 

[Java Demo](http://ideone.com/dUPSzP) 

[Regex Demo](https://regex101.com/r/mN2aA4/1)

---

**Regex Explanation:**

```
<.*?>
    < matches the characters < literally
    .*? matches any character (except newline)
        Quantifier: *? Between zero and unlimited times, as few times as possible, expanding as needed [lazy]
    > matches the characters > literally

```