java - Finding pairs in strings -


I was thinking that I could get some help with this problem. Let me have a string

  34342  

I want to get the number of joints in this string, which will be two. How will i do


EDIT: OK, what I really wanted was to match the events of the character which are similar in the string.

You can use to find things that appear in a row:

  (\ d +) \ 1  

It will again match the character of one or more digits by the same sequence. \ 1 is a duplication that first refers to the content of the capturing group.


If you want to match the number of times seen in the string, you can use it again, we are using a backreference, but this time we also have a Like a pattern

  (\ d) (? = \ D * \ 1)  

Use a well as a letterhead with a < Em> zero-quarters claim that specifies what should be matched (or neither matched) in the string after the current state Or, if you use a negative Lookout), but none of the characters or does not move the regex engine string position. In this case, we will claim that the contents of the first capture group should be met again, although not necessarily the first one near directly. By specifying \ d * within Lookahead, it will be treated as only one number, if it is within the same number (so if there is a space between the numbers, the pair did not match - if it can be changed in \ d to . , which will match any character).

It will match 3 and 4 in the first 34342 and 12332144 in the first 1, 2, 3, and 4. However, note that if you have a strange number of repetitions, you will receive an extra match (i.e.. 1112 will match the first two 1s), because look-aides are not used.


Comments