I understand how to use regex in Perl as follows:
$str =~ s/expression/replacement/g;
I understand that if any part of an expression is enclosed in parentheses, it can be used and written in the replacement part, for example:
$str =~ s/(a)/($1)dosomething/;
But is there a way to grab ($1) higher outside the regex expression?
I have a complete word, which is a string of consonants, for example. bEdmA , its vowel version of baEodamaA (where a and o are vowels), as well as its separate form of two tokens, separated by a space, bEd maA . I just want to get the vowel form of tokens from the full word, for example: beEoda , maA . I am trying to capture a token in full text expression, so I have:
$unvowelizedword = "bEdmA"; $tokens[0] = "bEd", $tokens[1] = "mA"; $vowelizedword = "baEodamA"; foreach $t(@tokens) {
I am trying to do something like this:
$vowelizedword = m/($t)/;
This is completely wrong for two reasons: the $t token is missing in its own form, such as bEd , but something like m/bEd/ would be more relevant. Also, how can I capture it in a variable outside the regular expression?
The real question is: how can I capture the baEoda and maA , given the bEd , mA tokens from the full word beEodamaA ?
Edit
I realized from all the answers that I missed two important details.
- Vowels are optional. So, if the tokens are “Al” and “ywm,” and the fully vowel is “Alyawmi,” then the output tokens will be “Al” and “yawmi.”
I mentioned only two vowels, but there are more, including two-character characters, like '~ a'. Full list (although I don't think I need to mention it here):
@vowels = ('a', 'i', 'u', 'o', '~', '~ a', '~ i', '~ u', 'N', 'F', 'K' , '~ N', '~ K');