add exception to a regex javascript












2















I'm doing a Romanian hyphenation script.
Previous question (solved) is here: regex if capture group matches string in case you want to take a look
This is a regex that deal with vowels that are not diphthongs or triphthongs:



(?:[aeiou])(?=[aeiou][bcdfghjklmnprstvwxyz]{0,})


I cannot seem to figure how to add two exceptions to this: "ii" in final position remain together. The "ii" group is usually preceded by a consonant, except in the case of "copiii" which is hyphenated -pi-ii
https://regex101.com/r/ew4JUh/1
The expected result, except for the word "copiii" is always a consonant (or more) followed by the "ii" group in the same syllable
muschii = mus-chii
pomii = po-mii



EDIT:



Just in case someone ever needs to do the same, you can find the script so far here:



https://playcode.io/156923



It works - mostly.



It implements the rules as I understand them. The only issue is that probably half the words stand in exception to the rules. So while the script does what it should, it cannot deal with exceptions that cannot be anticipated.



Ex:



avion = a-vi-on



iodat = io-dat



piatra = pia-tra



diamant = di-a-mant



And so on ad infinitum.
I don't believe there's any rule to establish when the vowels are grouped as diphthongs or triphthongs and when they belong to different syllables.



On the plus side I know more grammar and more regex than ever :)



Many thanks to Wiktor who helped immensely.










share|improve this question

























  • I think you are looking for (?!iib)[aeiou](?=[aeiou]), see demo.

    – Wiktor Stribiżew
    Nov 19 '18 at 12:44













  • Hello and thank you again. Add it as the answer. I liked the second better: regex101.com/r/ew4JUh/2

    – flish
    Nov 19 '18 at 12:49
















2















I'm doing a Romanian hyphenation script.
Previous question (solved) is here: regex if capture group matches string in case you want to take a look
This is a regex that deal with vowels that are not diphthongs or triphthongs:



(?:[aeiou])(?=[aeiou][bcdfghjklmnprstvwxyz]{0,})


I cannot seem to figure how to add two exceptions to this: "ii" in final position remain together. The "ii" group is usually preceded by a consonant, except in the case of "copiii" which is hyphenated -pi-ii
https://regex101.com/r/ew4JUh/1
The expected result, except for the word "copiii" is always a consonant (or more) followed by the "ii" group in the same syllable
muschii = mus-chii
pomii = po-mii



EDIT:



Just in case someone ever needs to do the same, you can find the script so far here:



https://playcode.io/156923



It works - mostly.



It implements the rules as I understand them. The only issue is that probably half the words stand in exception to the rules. So while the script does what it should, it cannot deal with exceptions that cannot be anticipated.



Ex:



avion = a-vi-on



iodat = io-dat



piatra = pia-tra



diamant = di-a-mant



And so on ad infinitum.
I don't believe there's any rule to establish when the vowels are grouped as diphthongs or triphthongs and when they belong to different syllables.



On the plus side I know more grammar and more regex than ever :)



Many thanks to Wiktor who helped immensely.










share|improve this question

























  • I think you are looking for (?!iib)[aeiou](?=[aeiou]), see demo.

    – Wiktor Stribiżew
    Nov 19 '18 at 12:44













  • Hello and thank you again. Add it as the answer. I liked the second better: regex101.com/r/ew4JUh/2

    – flish
    Nov 19 '18 at 12:49














2












2








2








I'm doing a Romanian hyphenation script.
Previous question (solved) is here: regex if capture group matches string in case you want to take a look
This is a regex that deal with vowels that are not diphthongs or triphthongs:



(?:[aeiou])(?=[aeiou][bcdfghjklmnprstvwxyz]{0,})


I cannot seem to figure how to add two exceptions to this: "ii" in final position remain together. The "ii" group is usually preceded by a consonant, except in the case of "copiii" which is hyphenated -pi-ii
https://regex101.com/r/ew4JUh/1
The expected result, except for the word "copiii" is always a consonant (or more) followed by the "ii" group in the same syllable
muschii = mus-chii
pomii = po-mii



EDIT:



Just in case someone ever needs to do the same, you can find the script so far here:



https://playcode.io/156923



It works - mostly.



It implements the rules as I understand them. The only issue is that probably half the words stand in exception to the rules. So while the script does what it should, it cannot deal with exceptions that cannot be anticipated.



Ex:



avion = a-vi-on



iodat = io-dat



piatra = pia-tra



diamant = di-a-mant



And so on ad infinitum.
I don't believe there's any rule to establish when the vowels are grouped as diphthongs or triphthongs and when they belong to different syllables.



On the plus side I know more grammar and more regex than ever :)



Many thanks to Wiktor who helped immensely.










share|improve this question
















I'm doing a Romanian hyphenation script.
Previous question (solved) is here: regex if capture group matches string in case you want to take a look
This is a regex that deal with vowels that are not diphthongs or triphthongs:



(?:[aeiou])(?=[aeiou][bcdfghjklmnprstvwxyz]{0,})


I cannot seem to figure how to add two exceptions to this: "ii" in final position remain together. The "ii" group is usually preceded by a consonant, except in the case of "copiii" which is hyphenated -pi-ii
https://regex101.com/r/ew4JUh/1
The expected result, except for the word "copiii" is always a consonant (or more) followed by the "ii" group in the same syllable
muschii = mus-chii
pomii = po-mii



EDIT:



Just in case someone ever needs to do the same, you can find the script so far here:



https://playcode.io/156923



It works - mostly.



It implements the rules as I understand them. The only issue is that probably half the words stand in exception to the rules. So while the script does what it should, it cannot deal with exceptions that cannot be anticipated.



Ex:



avion = a-vi-on



iodat = io-dat



piatra = pia-tra



diamant = di-a-mant



And so on ad infinitum.
I don't believe there's any rule to establish when the vowels are grouped as diphthongs or triphthongs and when they belong to different syllables.



On the plus side I know more grammar and more regex than ever :)



Many thanks to Wiktor who helped immensely.







javascript regex regex-group






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 14:46







flish

















asked Nov 19 '18 at 12:42









flishflish

4671614




4671614













  • I think you are looking for (?!iib)[aeiou](?=[aeiou]), see demo.

    – Wiktor Stribiżew
    Nov 19 '18 at 12:44













  • Hello and thank you again. Add it as the answer. I liked the second better: regex101.com/r/ew4JUh/2

    – flish
    Nov 19 '18 at 12:49



















  • I think you are looking for (?!iib)[aeiou](?=[aeiou]), see demo.

    – Wiktor Stribiżew
    Nov 19 '18 at 12:44













  • Hello and thank you again. Add it as the answer. I liked the second better: regex101.com/r/ew4JUh/2

    – flish
    Nov 19 '18 at 12:49

















I think you are looking for (?!iib)[aeiou](?=[aeiou]), see demo.

– Wiktor Stribiżew
Nov 19 '18 at 12:44







I think you are looking for (?!iib)[aeiou](?=[aeiou]), see demo.

– Wiktor Stribiżew
Nov 19 '18 at 12:44















Hello and thank you again. Add it as the answer. I liked the second better: regex101.com/r/ew4JUh/2

– flish
Nov 19 '18 at 12:49





Hello and thank you again. Add it as the answer. I liked the second better: regex101.com/r/ew4JUh/2

– flish
Nov 19 '18 at 12:49












1 Answer
1






active

oldest

votes


















2














You may use



(?!iib)[aeiou](?=[aeiou])


See the regex demo.



Note that [bcdfghjklmnprstvwxyz]{0,} at the end of the positive lookahead is redundant, it makes no difference if you require an optional pattern or not.



Details





  • (?!iib) - a negative lookahead that fails the match if, immediately to the right of the current location, there is ii followed with a word boundary


  • [aeiou] - a vowel


  • (?=[aeiou]) - that must be followed with another vowel.






share|improve this answer


























  • No, [bcdfghjklmnprstvwxyz]{0,} is not the right way to do it. What I wanted to say was that this rule applies only if these 2 vowels are not followed by another vowel. It should have been [^aeiou], right?

    – flish
    Nov 19 '18 at 12:54











  • @flish That restriction would not let matching i in piii. Are you sure you want that restriction?

    – Wiktor Stribiżew
    Nov 19 '18 at 12:57













  • It's complicated. What I want actually is to combine this here: (?!iib)(?:[aeiou])(?=[aeiou]) with the rest of the vowels rule : regex101.com/r/KPnEgy/1 (?:[aeo])(?=[iu][aeo])|(?:[aeiou])(?=([i][a][ui]|[e][ao]|[i][aeo]|[o][a]|[u][a]))

    – flish
    Nov 19 '18 at 13:00











  • @flish Sorry, this is not clear how you want to combine these regexps. BTW, the regex you posted above can be written as [aeo](?=[iu][aeo])|[aeiou](?=(?:ia[ui]|e[ao]|i[aeo]|[ou]a))

    – Wiktor Stribiżew
    Nov 19 '18 at 13:10













  • (?!iib)(?:[aeiou])(?=[aeiou]) this one splits 2 vowels in different syllables (except for ii in final position. The other one [aeo](?=[iu][aeo])|[aeiou](?=(?:ia[ui]|e[ao]|i[aeo]|[ou]a)) deals with diphthongs and triphthongs where vowels are followed by other vowels. Ideally they would be merged into a single regex which covers both cases. The problem is that this (?!iib)[aeiou](?=[aeiou]) would split to different syllables the vowels which need to remain together. I don't know how to put them together

    – flish
    Nov 19 '18 at 14:00











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374892%2fadd-exception-to-a-regex-javascript%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














You may use



(?!iib)[aeiou](?=[aeiou])


See the regex demo.



Note that [bcdfghjklmnprstvwxyz]{0,} at the end of the positive lookahead is redundant, it makes no difference if you require an optional pattern or not.



Details





  • (?!iib) - a negative lookahead that fails the match if, immediately to the right of the current location, there is ii followed with a word boundary


  • [aeiou] - a vowel


  • (?=[aeiou]) - that must be followed with another vowel.






share|improve this answer


























  • No, [bcdfghjklmnprstvwxyz]{0,} is not the right way to do it. What I wanted to say was that this rule applies only if these 2 vowels are not followed by another vowel. It should have been [^aeiou], right?

    – flish
    Nov 19 '18 at 12:54











  • @flish That restriction would not let matching i in piii. Are you sure you want that restriction?

    – Wiktor Stribiżew
    Nov 19 '18 at 12:57













  • It's complicated. What I want actually is to combine this here: (?!iib)(?:[aeiou])(?=[aeiou]) with the rest of the vowels rule : regex101.com/r/KPnEgy/1 (?:[aeo])(?=[iu][aeo])|(?:[aeiou])(?=([i][a][ui]|[e][ao]|[i][aeo]|[o][a]|[u][a]))

    – flish
    Nov 19 '18 at 13:00











  • @flish Sorry, this is not clear how you want to combine these regexps. BTW, the regex you posted above can be written as [aeo](?=[iu][aeo])|[aeiou](?=(?:ia[ui]|e[ao]|i[aeo]|[ou]a))

    – Wiktor Stribiżew
    Nov 19 '18 at 13:10













  • (?!iib)(?:[aeiou])(?=[aeiou]) this one splits 2 vowels in different syllables (except for ii in final position. The other one [aeo](?=[iu][aeo])|[aeiou](?=(?:ia[ui]|e[ao]|i[aeo]|[ou]a)) deals with diphthongs and triphthongs where vowels are followed by other vowels. Ideally they would be merged into a single regex which covers both cases. The problem is that this (?!iib)[aeiou](?=[aeiou]) would split to different syllables the vowels which need to remain together. I don't know how to put them together

    – flish
    Nov 19 '18 at 14:00
















2














You may use



(?!iib)[aeiou](?=[aeiou])


See the regex demo.



Note that [bcdfghjklmnprstvwxyz]{0,} at the end of the positive lookahead is redundant, it makes no difference if you require an optional pattern or not.



Details





  • (?!iib) - a negative lookahead that fails the match if, immediately to the right of the current location, there is ii followed with a word boundary


  • [aeiou] - a vowel


  • (?=[aeiou]) - that must be followed with another vowel.






share|improve this answer


























  • No, [bcdfghjklmnprstvwxyz]{0,} is not the right way to do it. What I wanted to say was that this rule applies only if these 2 vowels are not followed by another vowel. It should have been [^aeiou], right?

    – flish
    Nov 19 '18 at 12:54











  • @flish That restriction would not let matching i in piii. Are you sure you want that restriction?

    – Wiktor Stribiżew
    Nov 19 '18 at 12:57













  • It's complicated. What I want actually is to combine this here: (?!iib)(?:[aeiou])(?=[aeiou]) with the rest of the vowels rule : regex101.com/r/KPnEgy/1 (?:[aeo])(?=[iu][aeo])|(?:[aeiou])(?=([i][a][ui]|[e][ao]|[i][aeo]|[o][a]|[u][a]))

    – flish
    Nov 19 '18 at 13:00











  • @flish Sorry, this is not clear how you want to combine these regexps. BTW, the regex you posted above can be written as [aeo](?=[iu][aeo])|[aeiou](?=(?:ia[ui]|e[ao]|i[aeo]|[ou]a))

    – Wiktor Stribiżew
    Nov 19 '18 at 13:10













  • (?!iib)(?:[aeiou])(?=[aeiou]) this one splits 2 vowels in different syllables (except for ii in final position. The other one [aeo](?=[iu][aeo])|[aeiou](?=(?:ia[ui]|e[ao]|i[aeo]|[ou]a)) deals with diphthongs and triphthongs where vowels are followed by other vowels. Ideally they would be merged into a single regex which covers both cases. The problem is that this (?!iib)[aeiou](?=[aeiou]) would split to different syllables the vowels which need to remain together. I don't know how to put them together

    – flish
    Nov 19 '18 at 14:00














2












2








2







You may use



(?!iib)[aeiou](?=[aeiou])


See the regex demo.



Note that [bcdfghjklmnprstvwxyz]{0,} at the end of the positive lookahead is redundant, it makes no difference if you require an optional pattern or not.



Details





  • (?!iib) - a negative lookahead that fails the match if, immediately to the right of the current location, there is ii followed with a word boundary


  • [aeiou] - a vowel


  • (?=[aeiou]) - that must be followed with another vowel.






share|improve this answer















You may use



(?!iib)[aeiou](?=[aeiou])


See the regex demo.



Note that [bcdfghjklmnprstvwxyz]{0,} at the end of the positive lookahead is redundant, it makes no difference if you require an optional pattern or not.



Details





  • (?!iib) - a negative lookahead that fails the match if, immediately to the right of the current location, there is ii followed with a word boundary


  • [aeiou] - a vowel


  • (?=[aeiou]) - that must be followed with another vowel.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 19 '18 at 12:53

























answered Nov 19 '18 at 12:51









Wiktor StribiżewWiktor Stribiżew

313k16133210




313k16133210













  • No, [bcdfghjklmnprstvwxyz]{0,} is not the right way to do it. What I wanted to say was that this rule applies only if these 2 vowels are not followed by another vowel. It should have been [^aeiou], right?

    – flish
    Nov 19 '18 at 12:54











  • @flish That restriction would not let matching i in piii. Are you sure you want that restriction?

    – Wiktor Stribiżew
    Nov 19 '18 at 12:57













  • It's complicated. What I want actually is to combine this here: (?!iib)(?:[aeiou])(?=[aeiou]) with the rest of the vowels rule : regex101.com/r/KPnEgy/1 (?:[aeo])(?=[iu][aeo])|(?:[aeiou])(?=([i][a][ui]|[e][ao]|[i][aeo]|[o][a]|[u][a]))

    – flish
    Nov 19 '18 at 13:00











  • @flish Sorry, this is not clear how you want to combine these regexps. BTW, the regex you posted above can be written as [aeo](?=[iu][aeo])|[aeiou](?=(?:ia[ui]|e[ao]|i[aeo]|[ou]a))

    – Wiktor Stribiżew
    Nov 19 '18 at 13:10













  • (?!iib)(?:[aeiou])(?=[aeiou]) this one splits 2 vowels in different syllables (except for ii in final position. The other one [aeo](?=[iu][aeo])|[aeiou](?=(?:ia[ui]|e[ao]|i[aeo]|[ou]a)) deals with diphthongs and triphthongs where vowels are followed by other vowels. Ideally they would be merged into a single regex which covers both cases. The problem is that this (?!iib)[aeiou](?=[aeiou]) would split to different syllables the vowels which need to remain together. I don't know how to put them together

    – flish
    Nov 19 '18 at 14:00



















  • No, [bcdfghjklmnprstvwxyz]{0,} is not the right way to do it. What I wanted to say was that this rule applies only if these 2 vowels are not followed by another vowel. It should have been [^aeiou], right?

    – flish
    Nov 19 '18 at 12:54











  • @flish That restriction would not let matching i in piii. Are you sure you want that restriction?

    – Wiktor Stribiżew
    Nov 19 '18 at 12:57













  • It's complicated. What I want actually is to combine this here: (?!iib)(?:[aeiou])(?=[aeiou]) with the rest of the vowels rule : regex101.com/r/KPnEgy/1 (?:[aeo])(?=[iu][aeo])|(?:[aeiou])(?=([i][a][ui]|[e][ao]|[i][aeo]|[o][a]|[u][a]))

    – flish
    Nov 19 '18 at 13:00











  • @flish Sorry, this is not clear how you want to combine these regexps. BTW, the regex you posted above can be written as [aeo](?=[iu][aeo])|[aeiou](?=(?:ia[ui]|e[ao]|i[aeo]|[ou]a))

    – Wiktor Stribiżew
    Nov 19 '18 at 13:10













  • (?!iib)(?:[aeiou])(?=[aeiou]) this one splits 2 vowels in different syllables (except for ii in final position. The other one [aeo](?=[iu][aeo])|[aeiou](?=(?:ia[ui]|e[ao]|i[aeo]|[ou]a)) deals with diphthongs and triphthongs where vowels are followed by other vowels. Ideally they would be merged into a single regex which covers both cases. The problem is that this (?!iib)[aeiou](?=[aeiou]) would split to different syllables the vowels which need to remain together. I don't know how to put them together

    – flish
    Nov 19 '18 at 14:00

















No, [bcdfghjklmnprstvwxyz]{0,} is not the right way to do it. What I wanted to say was that this rule applies only if these 2 vowels are not followed by another vowel. It should have been [^aeiou], right?

– flish
Nov 19 '18 at 12:54





No, [bcdfghjklmnprstvwxyz]{0,} is not the right way to do it. What I wanted to say was that this rule applies only if these 2 vowels are not followed by another vowel. It should have been [^aeiou], right?

– flish
Nov 19 '18 at 12:54













@flish That restriction would not let matching i in piii. Are you sure you want that restriction?

– Wiktor Stribiżew
Nov 19 '18 at 12:57







@flish That restriction would not let matching i in piii. Are you sure you want that restriction?

– Wiktor Stribiżew
Nov 19 '18 at 12:57















It's complicated. What I want actually is to combine this here: (?!iib)(?:[aeiou])(?=[aeiou]) with the rest of the vowels rule : regex101.com/r/KPnEgy/1 (?:[aeo])(?=[iu][aeo])|(?:[aeiou])(?=([i][a][ui]|[e][ao]|[i][aeo]|[o][a]|[u][a]))

– flish
Nov 19 '18 at 13:00





It's complicated. What I want actually is to combine this here: (?!iib)(?:[aeiou])(?=[aeiou]) with the rest of the vowels rule : regex101.com/r/KPnEgy/1 (?:[aeo])(?=[iu][aeo])|(?:[aeiou])(?=([i][a][ui]|[e][ao]|[i][aeo]|[o][a]|[u][a]))

– flish
Nov 19 '18 at 13:00













@flish Sorry, this is not clear how you want to combine these regexps. BTW, the regex you posted above can be written as [aeo](?=[iu][aeo])|[aeiou](?=(?:ia[ui]|e[ao]|i[aeo]|[ou]a))

– Wiktor Stribiżew
Nov 19 '18 at 13:10







@flish Sorry, this is not clear how you want to combine these regexps. BTW, the regex you posted above can be written as [aeo](?=[iu][aeo])|[aeiou](?=(?:ia[ui]|e[ao]|i[aeo]|[ou]a))

– Wiktor Stribiżew
Nov 19 '18 at 13:10















(?!iib)(?:[aeiou])(?=[aeiou]) this one splits 2 vowels in different syllables (except for ii in final position. The other one [aeo](?=[iu][aeo])|[aeiou](?=(?:ia[ui]|e[ao]|i[aeo]|[ou]a)) deals with diphthongs and triphthongs where vowels are followed by other vowels. Ideally they would be merged into a single regex which covers both cases. The problem is that this (?!iib)[aeiou](?=[aeiou]) would split to different syllables the vowels which need to remain together. I don't know how to put them together

– flish
Nov 19 '18 at 14:00





(?!iib)(?:[aeiou])(?=[aeiou]) this one splits 2 vowels in different syllables (except for ii in final position. The other one [aeo](?=[iu][aeo])|[aeiou](?=(?:ia[ui]|e[ao]|i[aeo]|[ou]a)) deals with diphthongs and triphthongs where vowels are followed by other vowels. Ideally they would be merged into a single regex which covers both cases. The problem is that this (?!iib)[aeiou](?=[aeiou]) would split to different syllables the vowels which need to remain together. I don't know how to put them together

– flish
Nov 19 '18 at 14:00


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374892%2fadd-exception-to-a-regex-javascript%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to pass form data using jquery Ajax to insert data in database?

National Museum of Racing and Hall of Fame

Guess what letter conforming each word