Regex to match post-alveolar consonants

Viewed 59

I have a text file called a.txt that has this elements in it:

fall#i#1    fall (as a fruit) (v.)  fall    jatuh   fall (as a fruit) (v.)  jatuh*  t͡ʃampaʔ
dog#n#1 dog dog anjing  dog anjing  ŋand͡ʒi
wing#n#1    wing    wing    sayap   wing    sayap   kopaʔ
fly#i#1 fly (v.)    fly (vb)    terbang fly (v.)    terbang tobaŋ
mosquito#n#1    mosquito    mosquito    nyamuk  mosquito    nyamuk  ɲamuʔ
flower#n#2  flower  flower  bunga (yg jadi buah), kuntum    flower  bunga*  buŋo
sky#n#1 sky sky langit  sky langit* ʔlaŋɪt

First, I need a regular expression to match the lines that have final post-alveolar consonant like [ŋɡʔ] the out put should look like this:

fall#i#1    fall (as a fruit) (v.)  fall    jatuh   fall (as a fruit) (v.)  jatuh*  t͡ʃampaʔ
wing#n#1    wing    wing    sayap   wing    sayap   kopaʔ
fly#i#1 fly (v.)    fly (vb)    terbang fly (v.)    terbang tobaŋ
mosquito#n#1    mosquito    mosquito    nyamuk  mosquito    nyamuk  ɲamuʔ

Second, I need a regular expression to match the post-alveolar at the beginning of the words out put should look like this:

dog#n#1 dog dog anjing  dog anjing  ŋand͡ʒi
sky#n#1 sky sky langit  sky langit* ʔlaŋɪt

Third, I need a regular expression to match the post-alveolar between vowels like this output:

flower#n#2  flower  flower  bunga (yg jadi buah), kuntum    flower  bunga*  buŋo
sky#n#1 sky sky langit  sky langit* ʔlaŋɪt

I used to use this regex in Ubuntu terminal to match them all:

grep -P '\b[ʔŋɡk]|[ʔŋɡk]\b|[aiueo][ʔŋɡk][aiueo]' a.txt

but I couldn't find a regex to match them separately I mean once match post-alveolar at the end another regex match only at the beginning and the other regex match between vowels can any one please help me with that thanks

1 Answers

The regexps you can use are

grep -P '(*UCP)[ŋɡʔ]\b' file           # 1
grep -P '(*UCP)\b[ŋɡʔ]' file           # 2
grep -P '[aiɪueo][ʔŋɡk][aɪiueo]' file  # 3

Where

  • (*UCP)[ŋɡʔ]\b - matches ŋ, ɡ or ʔ followed with a Unicode-aware (due to (*UCP) PCRE verb) word boundary
  • (*UCP)\b[ŋɡʔ] - matches ŋ, ɡ or ʔ preceded with a Unicode-aware (due to (*UCP) PCRE verb) word boundary
  • [aiɪueo][ʔŋɡk][aɪiueo] matches ŋ, ɡ, k or ʔ in between a, i, ɪ, u, e and o vowels (NOTE i and ɪ are not the same letters!)

See a grep demo:

s='fall#i#1    fall (as a fruit) (v.)  fall    jatuh   fall (as a fruit) (v.)  jatuh*  t͡ʃampaʔ
dog#n#1 dog dog anjing  dog anjing  ŋand͡ʒi
wing#n#1    wing    wing    sayap   wing    sayap   kopaʔ
fly#i#1 fly (v.)    fly (vb)    terbang fly (v.)    terbang tobaŋ
mosquito#n#1    mosquito    mosquito    nyamuk  mosquito    nyamuk  ɲamuʔ
flower#n#2  flower  flower  bunga (yg jadi buah), kuntum    flower  bunga*  buŋo
sky#n#1 sky sky langit  sky langit* ʔlaŋɪt'
grep -P '(*UCP)[ŋɡʔ]\b' <<< "$s"
echo "----"
grep -P '(*UCP)\b[ŋɡʔ]' <<< "$s"
echo "----"
grep -P '[aiɪueo][ʔŋɡk][aɪiueo]' <<< "$s"

Output:

fall#i#1    fall (as a fruit) (v.)  fall    jatuh   fall (as a fruit) (v.)  jatuh*  t͡ʃampaʔ
wing#n#1    wing    wing    sayap   wing    sayap   kopaʔ
fly#i#1 fly (v.)    fly (vb)    terbang fly (v.)    terbang tobaŋ
mosquito#n#1    mosquito    mosquito    nyamuk  mosquito    nyamuk  ɲamuʔ
----
dog#n#1 dog dog anjing  dog anjing  ŋand͡ʒi
sky#n#1 sky sky langit  sky langit* ʔlaŋɪt
----
flower#n#2  flower  flower  bunga (yg jadi buah), kuntum    flower  bunga*  buŋo
sky#n#1 sky sky langit  sky langit* ʔlaŋɪt
Related