Regex for matching matches

For a linguistics project, I am trying to match all occurrences of one or two consonants between vowels in some text. I am trying to write a very simple match in PHP ( preg_match_all), but after the match is destroyed, it will not be able to match again.

The following is very simple and should do the trick, but only match the first occurrence:

[aeiou](qu|[bcdfghjklmnprstvwxyz]{1,2})[aeiou]

In: officiosior: offiand osicome back, but not icibecause the end iis the first part of the match in the second match.

As far as I can tell, this is impossible to do, but is there a decent way to get around the problem?

+4
source share
1 answer

.

(?=([aeiou](?:qu|[^aeiou]{1,2})[aeiou]))

. , , . ...

(?=                    # look ahead to see if there is:
  (                    #   group and capture to \1:
    [aeiou]            #     any character of: 'a', 'e', 'i', 'o', 'u'
    (?:                #     group, but do not capture:
      qu               #       'qu'
     |                 #      OR
      [^aeiou]{1,2}    #       any character except: 'a', 'e', 'i', 'o', 'u' 
                       #       (between 1 and 2 times)
    )                  #     end of grouping
    [aeiou]            #     any character of: 'a', 'e', 'i', 'o', 'u'
  )                    #   end of \1
)                      # end of look-ahead

+8

Source: https://habr.com/ru/post/1547484/


All Articles