Regular expression to match a string and some letters [duplicate]












0
















This question already has an answer here:




  • Regular Expression to Match String Exactly?

    5 answers




I am trying to find a regular expression for a Flex program that would match a "string " and a sequence of letters that exist in the range [A-E].



What i m trying to do is get the cases that the input has the "string " and either 1 or 2 or 4 or more than 4 letters that exist in the range [A-E].**<



What i have tried so far is the regular expression: "string "([A-E]{1,2}|[A-E]{4,})
The case that the letters are in the range {4,} obviously works however the case {1,2} doesn't since if the user gives into the input "string "ABC it will invoke the case [A-E]{1,2}.



I thought about using a regular expression with a NOT operator something along the lines of : "string "(NOT OPERATOR)([A-E]{3}) so that i would be getting every case that the "string " is followed by anything else that 3 letters, but it turns out there is not such operator.



What can i do to solve this problem?



Thanks in advance for any answer given!










share|improve this question















marked as duplicate by Wiktor Stribiżew regex
Users with the  regex badge can single-handedly close regex questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 20:20


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    Looks like "string "([A-E]{1,2}|[A-E]{4,})b might work.

    – Wiktor Stribiżew
    Jan 2 at 19:17











  • What about this string "string "ABZ should it match or not? If it should not, then boundary condition will not work.

    – Pushpesh Kumar Rajwanshi
    Jan 2 at 19:37













  • All this is part of an excersise and it is assumed that the user wont type any letter other than the ones in range [A-E].So we know that ABZ will never be a given input.

    – dimpap
    Jan 2 at 19:54
















0
















This question already has an answer here:




  • Regular Expression to Match String Exactly?

    5 answers




I am trying to find a regular expression for a Flex program that would match a "string " and a sequence of letters that exist in the range [A-E].



What i m trying to do is get the cases that the input has the "string " and either 1 or 2 or 4 or more than 4 letters that exist in the range [A-E].**<



What i have tried so far is the regular expression: "string "([A-E]{1,2}|[A-E]{4,})
The case that the letters are in the range {4,} obviously works however the case {1,2} doesn't since if the user gives into the input "string "ABC it will invoke the case [A-E]{1,2}.



I thought about using a regular expression with a NOT operator something along the lines of : "string "(NOT OPERATOR)([A-E]{3}) so that i would be getting every case that the "string " is followed by anything else that 3 letters, but it turns out there is not such operator.



What can i do to solve this problem?



Thanks in advance for any answer given!










share|improve this question















marked as duplicate by Wiktor Stribiżew regex
Users with the  regex badge can single-handedly close regex questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 20:20


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    Looks like "string "([A-E]{1,2}|[A-E]{4,})b might work.

    – Wiktor Stribiżew
    Jan 2 at 19:17











  • What about this string "string "ABZ should it match or not? If it should not, then boundary condition will not work.

    – Pushpesh Kumar Rajwanshi
    Jan 2 at 19:37













  • All this is part of an excersise and it is assumed that the user wont type any letter other than the ones in range [A-E].So we know that ABZ will never be a given input.

    – dimpap
    Jan 2 at 19:54














0












0








0









This question already has an answer here:




  • Regular Expression to Match String Exactly?

    5 answers




I am trying to find a regular expression for a Flex program that would match a "string " and a sequence of letters that exist in the range [A-E].



What i m trying to do is get the cases that the input has the "string " and either 1 or 2 or 4 or more than 4 letters that exist in the range [A-E].**<



What i have tried so far is the regular expression: "string "([A-E]{1,2}|[A-E]{4,})
The case that the letters are in the range {4,} obviously works however the case {1,2} doesn't since if the user gives into the input "string "ABC it will invoke the case [A-E]{1,2}.



I thought about using a regular expression with a NOT operator something along the lines of : "string "(NOT OPERATOR)([A-E]{3}) so that i would be getting every case that the "string " is followed by anything else that 3 letters, but it turns out there is not such operator.



What can i do to solve this problem?



Thanks in advance for any answer given!










share|improve this question

















This question already has an answer here:




  • Regular Expression to Match String Exactly?

    5 answers




I am trying to find a regular expression for a Flex program that would match a "string " and a sequence of letters that exist in the range [A-E].



What i m trying to do is get the cases that the input has the "string " and either 1 or 2 or 4 or more than 4 letters that exist in the range [A-E].**<



What i have tried so far is the regular expression: "string "([A-E]{1,2}|[A-E]{4,})
The case that the letters are in the range {4,} obviously works however the case {1,2} doesn't since if the user gives into the input "string "ABC it will invoke the case [A-E]{1,2}.



I thought about using a regular expression with a NOT operator something along the lines of : "string "(NOT OPERATOR)([A-E]{3}) so that i would be getting every case that the "string " is followed by anything else that 3 letters, but it turns out there is not such operator.



What can i do to solve this problem?



Thanks in advance for any answer given!





This question already has an answer here:




  • Regular Expression to Match String Exactly?

    5 answers








regex






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 19:22









Aaron_ab

1,26421224




1,26421224










asked Jan 2 at 19:13









dimpapdimpap

124




124




marked as duplicate by Wiktor Stribiżew regex
Users with the  regex badge can single-handedly close regex questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 20:20


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Wiktor Stribiżew regex
Users with the  regex badge can single-handedly close regex questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 20:20


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1





    Looks like "string "([A-E]{1,2}|[A-E]{4,})b might work.

    – Wiktor Stribiżew
    Jan 2 at 19:17











  • What about this string "string "ABZ should it match or not? If it should not, then boundary condition will not work.

    – Pushpesh Kumar Rajwanshi
    Jan 2 at 19:37













  • All this is part of an excersise and it is assumed that the user wont type any letter other than the ones in range [A-E].So we know that ABZ will never be a given input.

    – dimpap
    Jan 2 at 19:54














  • 1





    Looks like "string "([A-E]{1,2}|[A-E]{4,})b might work.

    – Wiktor Stribiżew
    Jan 2 at 19:17











  • What about this string "string "ABZ should it match or not? If it should not, then boundary condition will not work.

    – Pushpesh Kumar Rajwanshi
    Jan 2 at 19:37













  • All this is part of an excersise and it is assumed that the user wont type any letter other than the ones in range [A-E].So we know that ABZ will never be a given input.

    – dimpap
    Jan 2 at 19:54








1




1





Looks like "string "([A-E]{1,2}|[A-E]{4,})b might work.

– Wiktor Stribiżew
Jan 2 at 19:17





Looks like "string "([A-E]{1,2}|[A-E]{4,})b might work.

– Wiktor Stribiżew
Jan 2 at 19:17













What about this string "string "ABZ should it match or not? If it should not, then boundary condition will not work.

– Pushpesh Kumar Rajwanshi
Jan 2 at 19:37







What about this string "string "ABZ should it match or not? If it should not, then boundary condition will not work.

– Pushpesh Kumar Rajwanshi
Jan 2 at 19:37















All this is part of an excersise and it is assumed that the user wont type any letter other than the ones in range [A-E].So we know that ABZ will never be a given input.

– dimpap
Jan 2 at 19:54





All this is part of an excersise and it is assumed that the user wont type any letter other than the ones in range [A-E].So we know that ABZ will never be a given input.

– dimpap
Jan 2 at 19:54












2 Answers
2






active

oldest

votes


















0














Yes, the string "ABC" matches [A-E]{1,2} because you don't insist that those letters are the only thing in the specified string (hence, "AB" matches and "C" just gets lumped in there for some other reason). You should insist that when the regex is done, you've reached the end of the line/string:



^string ([A-E]{1,2}|[A-E]{4})$


or at least some sort of word boundary:



string ([A-E]{1,2}|[A-E]{4})b





share|improve this answer































    0














    Your regex is almost fine, just enforce the next letter to be not in your group, to prevent the ABC problem:



    "string "([A-E]{1,2}|[A-E]{4,})[^A-E]


    If this is the end of the string, you need to check for that as well:



    "string "([A-E]{1,2}|[A-E]{4,})([^A-E]|$)





    share|improve this answer






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Yes, the string "ABC" matches [A-E]{1,2} because you don't insist that those letters are the only thing in the specified string (hence, "AB" matches and "C" just gets lumped in there for some other reason). You should insist that when the regex is done, you've reached the end of the line/string:



      ^string ([A-E]{1,2}|[A-E]{4})$


      or at least some sort of word boundary:



      string ([A-E]{1,2}|[A-E]{4})b





      share|improve this answer




























        0














        Yes, the string "ABC" matches [A-E]{1,2} because you don't insist that those letters are the only thing in the specified string (hence, "AB" matches and "C" just gets lumped in there for some other reason). You should insist that when the regex is done, you've reached the end of the line/string:



        ^string ([A-E]{1,2}|[A-E]{4})$


        or at least some sort of word boundary:



        string ([A-E]{1,2}|[A-E]{4})b





        share|improve this answer


























          0












          0








          0







          Yes, the string "ABC" matches [A-E]{1,2} because you don't insist that those letters are the only thing in the specified string (hence, "AB" matches and "C" just gets lumped in there for some other reason). You should insist that when the regex is done, you've reached the end of the line/string:



          ^string ([A-E]{1,2}|[A-E]{4})$


          or at least some sort of word boundary:



          string ([A-E]{1,2}|[A-E]{4})b





          share|improve this answer













          Yes, the string "ABC" matches [A-E]{1,2} because you don't insist that those letters are the only thing in the specified string (hence, "AB" matches and "C" just gets lumped in there for some other reason). You should insist that when the regex is done, you've reached the end of the line/string:



          ^string ([A-E]{1,2}|[A-E]{4})$


          or at least some sort of word boundary:



          string ([A-E]{1,2}|[A-E]{4})b






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 2 at 19:22









          scnerdscnerd

          3,41411126




          3,41411126

























              0














              Your regex is almost fine, just enforce the next letter to be not in your group, to prevent the ABC problem:



              "string "([A-E]{1,2}|[A-E]{4,})[^A-E]


              If this is the end of the string, you need to check for that as well:



              "string "([A-E]{1,2}|[A-E]{4,})([^A-E]|$)





              share|improve this answer




























                0














                Your regex is almost fine, just enforce the next letter to be not in your group, to prevent the ABC problem:



                "string "([A-E]{1,2}|[A-E]{4,})[^A-E]


                If this is the end of the string, you need to check for that as well:



                "string "([A-E]{1,2}|[A-E]{4,})([^A-E]|$)





                share|improve this answer


























                  0












                  0








                  0







                  Your regex is almost fine, just enforce the next letter to be not in your group, to prevent the ABC problem:



                  "string "([A-E]{1,2}|[A-E]{4,})[^A-E]


                  If this is the end of the string, you need to check for that as well:



                  "string "([A-E]{1,2}|[A-E]{4,})([^A-E]|$)





                  share|improve this answer













                  Your regex is almost fine, just enforce the next letter to be not in your group, to prevent the ABC problem:



                  "string "([A-E]{1,2}|[A-E]{4,})[^A-E]


                  If this is the end of the string, you need to check for that as well:



                  "string "([A-E]{1,2}|[A-E]{4,})([^A-E]|$)






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 2 at 19:16









                  kabanuskabanus

                  12.4k31542




                  12.4k31542















                      Popular posts from this blog

                      MongoDB - Not Authorized To Execute Command

                      How to fix TextFormField cause rebuild widget in Flutter

                      Npm cannot find a required file even through it is in the searched directory