not the group of oracle regular expression












1















I am looking to have a not of regular expression group in oracle regular expression query. Meaning I want to match all patterns that do not match the regular expression group



My String:



"G,1 = G"


Pattern matching used:



([[:alpha:]]+,*[[:digit:]]*)


Current_Output:



"grouped(G,-1) = grouped(G)"


The Problem: Not the Pattern. Match all expression that does not match



([[:alpha:]]+,*[[:digit:]]*)


Required Output for the above expression:



"G,-1 group(=) G"


Other factors: The "=" may be any operator "(+-*=)"



The Code:



SELECT  REGEXP_REPLACE('G,-1 = G',
'([[:alpha:]]+,*[[:digit:]]*)',
'grouped(1)')

as "REGEXP_REPLACE_Concatenation"
FROM dual;


I would appreciate if any would help derive a Not in the regular expression.










share|improve this question

























  • Please check my answer and accept/upvote it if it worked for you so that it would also help others seeking answers.Please read : stackoverflow.com/help/someone-answers

    – Kaushik Nayak
    Dec 19 '18 at 15:50
















1















I am looking to have a not of regular expression group in oracle regular expression query. Meaning I want to match all patterns that do not match the regular expression group



My String:



"G,1 = G"


Pattern matching used:



([[:alpha:]]+,*[[:digit:]]*)


Current_Output:



"grouped(G,-1) = grouped(G)"


The Problem: Not the Pattern. Match all expression that does not match



([[:alpha:]]+,*[[:digit:]]*)


Required Output for the above expression:



"G,-1 group(=) G"


Other factors: The "=" may be any operator "(+-*=)"



The Code:



SELECT  REGEXP_REPLACE('G,-1 = G',
'([[:alpha:]]+,*[[:digit:]]*)',
'grouped(1)')

as "REGEXP_REPLACE_Concatenation"
FROM dual;


I would appreciate if any would help derive a Not in the regular expression.










share|improve this question

























  • Please check my answer and accept/upvote it if it worked for you so that it would also help others seeking answers.Please read : stackoverflow.com/help/someone-answers

    – Kaushik Nayak
    Dec 19 '18 at 15:50














1












1








1








I am looking to have a not of regular expression group in oracle regular expression query. Meaning I want to match all patterns that do not match the regular expression group



My String:



"G,1 = G"


Pattern matching used:



([[:alpha:]]+,*[[:digit:]]*)


Current_Output:



"grouped(G,-1) = grouped(G)"


The Problem: Not the Pattern. Match all expression that does not match



([[:alpha:]]+,*[[:digit:]]*)


Required Output for the above expression:



"G,-1 group(=) G"


Other factors: The "=" may be any operator "(+-*=)"



The Code:



SELECT  REGEXP_REPLACE('G,-1 = G',
'([[:alpha:]]+,*[[:digit:]]*)',
'grouped(1)')

as "REGEXP_REPLACE_Concatenation"
FROM dual;


I would appreciate if any would help derive a Not in the regular expression.










share|improve this question
















I am looking to have a not of regular expression group in oracle regular expression query. Meaning I want to match all patterns that do not match the regular expression group



My String:



"G,1 = G"


Pattern matching used:



([[:alpha:]]+,*[[:digit:]]*)


Current_Output:



"grouped(G,-1) = grouped(G)"


The Problem: Not the Pattern. Match all expression that does not match



([[:alpha:]]+,*[[:digit:]]*)


Required Output for the above expression:



"G,-1 group(=) G"


Other factors: The "=" may be any operator "(+-*=)"



The Code:



SELECT  REGEXP_REPLACE('G,-1 = G',
'([[:alpha:]]+,*[[:digit:]]*)',
'grouped(1)')

as "REGEXP_REPLACE_Concatenation"
FROM dual;


I would appreciate if any would help derive a Not in the regular expression.







oracle regex-negation






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 2:34









lagom

3,636102037




3,636102037










asked Nov 21 '18 at 20:54









Anil VillamkandathilAnil Villamkandathil

111




111













  • Please check my answer and accept/upvote it if it worked for you so that it would also help others seeking answers.Please read : stackoverflow.com/help/someone-answers

    – Kaushik Nayak
    Dec 19 '18 at 15:50



















  • Please check my answer and accept/upvote it if it worked for you so that it would also help others seeking answers.Please read : stackoverflow.com/help/someone-answers

    – Kaushik Nayak
    Dec 19 '18 at 15:50

















Please check my answer and accept/upvote it if it worked for you so that it would also help others seeking answers.Please read : stackoverflow.com/help/someone-answers

– Kaushik Nayak
Dec 19 '18 at 15:50





Please check my answer and accept/upvote it if it worked for you so that it would also help others seeking answers.Please read : stackoverflow.com/help/someone-answers

– Kaushik Nayak
Dec 19 '18 at 15:50












1 Answer
1






active

oldest

votes


















0














You may try this pattern :



REGEXP_REPLACE(s,'([a-zA-Z]+,[0-9]+s+)([^a-zA-Z0-9])(s+[a-zA-Z]+)','1group(2)3')



I have not used Posix regex which you were using for simplicity and used [a-zA-Z] for alphabet and [0-9] for digits.
s*? represents zero or more space.



[^a-zA-Z0-9] tries to match your operator, but it may match other than your valid operators, so you may explicitly specify them as (+|-|*|=) instead if you're sure about all the operators possible.



I have put left hand operand, operator and right hand operator as groups (1),(2) and (3) respectively.



SQL>
SQL> with t(s) AS
2 (
3 SELECT 'G,1=G' FROM DUAL UNION ALL
4 SELECT 'AB,13 + H' FROM DUAL UNION ALL
5 SELECT 'BCD,1 * ID' FROM DUAL
6 )
7 select s,REGEXP_REPLACE(s,'([a-zA-Z]+,[0-9]+s*?)([^a-zA-Z0-9])(s*?[a-zA-Z]+)'
8 ,'1group(2)3')
9 as m
10 FROM t;

S M
-- --
G,1=G G,1group(=)G
AB,13 + H AB,13 group(+) H
BCD,1 * ID BCD,1 group(*) ID


Demo



Also, If you do not wish the pattern to be specific before or after the operator and only wish to group the operator, you may use:



REGEXP_REPLACE(s,'([^+-*=]+)(+|-|*|=)([^+-*=]+)'
,'1group(2)3')






share|improve this answer

























    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%2f53420339%2fnot-the-group-of-oracle-regular-expression%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









    0














    You may try this pattern :



    REGEXP_REPLACE(s,'([a-zA-Z]+,[0-9]+s+)([^a-zA-Z0-9])(s+[a-zA-Z]+)','1group(2)3')



    I have not used Posix regex which you were using for simplicity and used [a-zA-Z] for alphabet and [0-9] for digits.
    s*? represents zero or more space.



    [^a-zA-Z0-9] tries to match your operator, but it may match other than your valid operators, so you may explicitly specify them as (+|-|*|=) instead if you're sure about all the operators possible.



    I have put left hand operand, operator and right hand operator as groups (1),(2) and (3) respectively.



    SQL>
    SQL> with t(s) AS
    2 (
    3 SELECT 'G,1=G' FROM DUAL UNION ALL
    4 SELECT 'AB,13 + H' FROM DUAL UNION ALL
    5 SELECT 'BCD,1 * ID' FROM DUAL
    6 )
    7 select s,REGEXP_REPLACE(s,'([a-zA-Z]+,[0-9]+s*?)([^a-zA-Z0-9])(s*?[a-zA-Z]+)'
    8 ,'1group(2)3')
    9 as m
    10 FROM t;

    S M
    -- --
    G,1=G G,1group(=)G
    AB,13 + H AB,13 group(+) H
    BCD,1 * ID BCD,1 group(*) ID


    Demo



    Also, If you do not wish the pattern to be specific before or after the operator and only wish to group the operator, you may use:



    REGEXP_REPLACE(s,'([^+-*=]+)(+|-|*|=)([^+-*=]+)'
    ,'1group(2)3')






    share|improve this answer






























      0














      You may try this pattern :



      REGEXP_REPLACE(s,'([a-zA-Z]+,[0-9]+s+)([^a-zA-Z0-9])(s+[a-zA-Z]+)','1group(2)3')



      I have not used Posix regex which you were using for simplicity and used [a-zA-Z] for alphabet and [0-9] for digits.
      s*? represents zero or more space.



      [^a-zA-Z0-9] tries to match your operator, but it may match other than your valid operators, so you may explicitly specify them as (+|-|*|=) instead if you're sure about all the operators possible.



      I have put left hand operand, operator and right hand operator as groups (1),(2) and (3) respectively.



      SQL>
      SQL> with t(s) AS
      2 (
      3 SELECT 'G,1=G' FROM DUAL UNION ALL
      4 SELECT 'AB,13 + H' FROM DUAL UNION ALL
      5 SELECT 'BCD,1 * ID' FROM DUAL
      6 )
      7 select s,REGEXP_REPLACE(s,'([a-zA-Z]+,[0-9]+s*?)([^a-zA-Z0-9])(s*?[a-zA-Z]+)'
      8 ,'1group(2)3')
      9 as m
      10 FROM t;

      S M
      -- --
      G,1=G G,1group(=)G
      AB,13 + H AB,13 group(+) H
      BCD,1 * ID BCD,1 group(*) ID


      Demo



      Also, If you do not wish the pattern to be specific before or after the operator and only wish to group the operator, you may use:



      REGEXP_REPLACE(s,'([^+-*=]+)(+|-|*|=)([^+-*=]+)'
      ,'1group(2)3')






      share|improve this answer




























        0












        0








        0







        You may try this pattern :



        REGEXP_REPLACE(s,'([a-zA-Z]+,[0-9]+s+)([^a-zA-Z0-9])(s+[a-zA-Z]+)','1group(2)3')



        I have not used Posix regex which you were using for simplicity and used [a-zA-Z] for alphabet and [0-9] for digits.
        s*? represents zero or more space.



        [^a-zA-Z0-9] tries to match your operator, but it may match other than your valid operators, so you may explicitly specify them as (+|-|*|=) instead if you're sure about all the operators possible.



        I have put left hand operand, operator and right hand operator as groups (1),(2) and (3) respectively.



        SQL>
        SQL> with t(s) AS
        2 (
        3 SELECT 'G,1=G' FROM DUAL UNION ALL
        4 SELECT 'AB,13 + H' FROM DUAL UNION ALL
        5 SELECT 'BCD,1 * ID' FROM DUAL
        6 )
        7 select s,REGEXP_REPLACE(s,'([a-zA-Z]+,[0-9]+s*?)([^a-zA-Z0-9])(s*?[a-zA-Z]+)'
        8 ,'1group(2)3')
        9 as m
        10 FROM t;

        S M
        -- --
        G,1=G G,1group(=)G
        AB,13 + H AB,13 group(+) H
        BCD,1 * ID BCD,1 group(*) ID


        Demo



        Also, If you do not wish the pattern to be specific before or after the operator and only wish to group the operator, you may use:



        REGEXP_REPLACE(s,'([^+-*=]+)(+|-|*|=)([^+-*=]+)'
        ,'1group(2)3')






        share|improve this answer















        You may try this pattern :



        REGEXP_REPLACE(s,'([a-zA-Z]+,[0-9]+s+)([^a-zA-Z0-9])(s+[a-zA-Z]+)','1group(2)3')



        I have not used Posix regex which you were using for simplicity and used [a-zA-Z] for alphabet and [0-9] for digits.
        s*? represents zero or more space.



        [^a-zA-Z0-9] tries to match your operator, but it may match other than your valid operators, so you may explicitly specify them as (+|-|*|=) instead if you're sure about all the operators possible.



        I have put left hand operand, operator and right hand operator as groups (1),(2) and (3) respectively.



        SQL>
        SQL> with t(s) AS
        2 (
        3 SELECT 'G,1=G' FROM DUAL UNION ALL
        4 SELECT 'AB,13 + H' FROM DUAL UNION ALL
        5 SELECT 'BCD,1 * ID' FROM DUAL
        6 )
        7 select s,REGEXP_REPLACE(s,'([a-zA-Z]+,[0-9]+s*?)([^a-zA-Z0-9])(s*?[a-zA-Z]+)'
        8 ,'1group(2)3')
        9 as m
        10 FROM t;

        S M
        -- --
        G,1=G G,1group(=)G
        AB,13 + H AB,13 group(+) H
        BCD,1 * ID BCD,1 group(*) ID


        Demo



        Also, If you do not wish the pattern to be specific before or after the operator and only wish to group the operator, you may use:



        REGEXP_REPLACE(s,'([^+-*=]+)(+|-|*|=)([^+-*=]+)'
        ,'1group(2)3')







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 22 '18 at 3:51

























        answered Nov 22 '18 at 3:44









        Kaushik NayakKaushik Nayak

        18.6k41230




        18.6k41230






























            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%2f53420339%2fnot-the-group-of-oracle-regular-expression%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

            Create new schema in PostgreSQL using DBeaver

            Deepest pit of an array with Javascript: test on Codility

            Costa Masnaga