match each occurrence of a dot until a single colonMatch all occurrences of a regexWhat regex will match every character except comma ',' or semi-colon ';'?Regex: matching up to the first occurrence of a characterHow to match “anything up until this sequence of characters” in a regular expression?Finding @mentions in stringPHP - preg_replace not matching multiple occurrencesJavascript: Some kind of preg_match with a callback on each match?regular expression replace all except captured expressionHow to match until first occurrence of a pattern?Match between two single quotes and continue matching if two single quotes appear in a row or if '.' appears in the middle?

Why didn't Boeing produce its own regional jet?

What is the most common color to indicate the input-field is disabled?

What Exploit Are These User Agents Trying to Use?

Venezuelan girlfriend wants to travel the USA to be with me. What is the process?

How can I deal with my CEO asking me to hire someone with a higher salary than me, a co-founder?

Finitely generated matrix groups whose eigenvalues are all algebraic

Rotate ASCII Art by 45 Degrees

How to stretch the corners of this image so that it looks like a perfect rectangle?

How to find if SQL server backup is encrypted with TDE without restoring the backup

How do I exit BASH while loop using modulus operator?

How to show a landlord what we have in savings?

Notepad++ delete until colon for every line with replace all

How could indestructible materials be used in power generation?

How exploitable/balanced is this homebrew spell: Spell Permanency?

What are the G forces leaving Earth orbit?

Can a virus destroy the BIOS of a modern computer?

Implication of namely

files created then deleted at every second in tmp directory

Why do I get negative height?

GFCI outlets - can they be repaired? Are they really needed at the end of a circuit?

How does a refinance allow a mortgage to be repaid?

Are British MPs missing the point, with these 'Indicative Votes'?

Bullying boss launched a smear campaign and made me unemployable

How seriously should I take size and weight limits of hand luggage?



match each occurrence of a dot until a single colon


Match all occurrences of a regexWhat regex will match every character except comma ',' or semi-colon ';'?Regex: matching up to the first occurrence of a characterHow to match “anything up until this sequence of characters” in a regular expression?Finding @mentions in stringPHP - preg_replace not matching multiple occurrencesJavascript: Some kind of preg_match with a callback on each match?regular expression replace all except captured expressionHow to match until first occurrence of a pattern?Match between two single quotes and continue matching if two single quotes appear in a row or if '.' appears in the middle?













0















Take this string



bob.ted.dave.allan::james.fred: hello.dave



I need to replace each occurrence of . with # until I hit a singular ":" not stopping at the namespace '::' but just the ":"



So in the above string, the end result will be
bob#ted#dave#allan::james#fred: hello.dave



currently I have [.] which matches all dots in the string but cant get it to anchor on the single ":"










share|improve this question


























    0















    Take this string



    bob.ted.dave.allan::james.fred: hello.dave



    I need to replace each occurrence of . with # until I hit a singular ":" not stopping at the namespace '::' but just the ":"



    So in the above string, the end result will be
    bob#ted#dave#allan::james#fred: hello.dave



    currently I have [.] which matches all dots in the string but cant get it to anchor on the single ":"










    share|improve this question
























      0












      0








      0








      Take this string



      bob.ted.dave.allan::james.fred: hello.dave



      I need to replace each occurrence of . with # until I hit a singular ":" not stopping at the namespace '::' but just the ":"



      So in the above string, the end result will be
      bob#ted#dave#allan::james#fred: hello.dave



      currently I have [.] which matches all dots in the string but cant get it to anchor on the single ":"










      share|improve this question














      Take this string



      bob.ted.dave.allan::james.fred: hello.dave



      I need to replace each occurrence of . with # until I hit a singular ":" not stopping at the namespace '::' but just the ":"



      So in the above string, the end result will be
      bob#ted#dave#allan::james#fred: hello.dave



      currently I have [.] which matches all dots in the string but cant get it to anchor on the single ":"







      regex






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 21:19









      fmanfman

      41




      41






















          3 Answers
          3






          active

          oldest

          votes


















          1














          If you want a pure regex solution this can only be done with a variable-width lookbehind pattern, which is supported by only a few regex engines:



          (?<!(?<!:):(?!:).*).


          Demo: https://regex101.com/r/Crq49C/2



          Or if there is always going to be a colon, you can use a positive lookahead pattern instead:



          .(?=.*(?<!:):(?!:))


          Demo: https://regex101.com/r/Crq49C/3






          share|improve this answer
































            0














            To just anchor on a single . and not stop until seeing exactly one : I think
            [.](?=.*:1)
            will work.
            This does not work if there is more than one : on a line.






            share|improve this answer






























              0














              You can capture the entire string up until the single : with a simple character set match:



              [w. :]+(?::1)



              Then do a replace on all of the .'s in the captured string.



              Demo: https://regex101.com/r/xDfstu/1






              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%2f55052961%2fmatch-each-occurrence-of-a-dot-until-a-single-colon%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                1














                If you want a pure regex solution this can only be done with a variable-width lookbehind pattern, which is supported by only a few regex engines:



                (?<!(?<!:):(?!:).*).


                Demo: https://regex101.com/r/Crq49C/2



                Or if there is always going to be a colon, you can use a positive lookahead pattern instead:



                .(?=.*(?<!:):(?!:))


                Demo: https://regex101.com/r/Crq49C/3






                share|improve this answer





























                  1














                  If you want a pure regex solution this can only be done with a variable-width lookbehind pattern, which is supported by only a few regex engines:



                  (?<!(?<!:):(?!:).*).


                  Demo: https://regex101.com/r/Crq49C/2



                  Or if there is always going to be a colon, you can use a positive lookahead pattern instead:



                  .(?=.*(?<!:):(?!:))


                  Demo: https://regex101.com/r/Crq49C/3






                  share|improve this answer



























                    1












                    1








                    1







                    If you want a pure regex solution this can only be done with a variable-width lookbehind pattern, which is supported by only a few regex engines:



                    (?<!(?<!:):(?!:).*).


                    Demo: https://regex101.com/r/Crq49C/2



                    Or if there is always going to be a colon, you can use a positive lookahead pattern instead:



                    .(?=.*(?<!:):(?!:))


                    Demo: https://regex101.com/r/Crq49C/3






                    share|improve this answer















                    If you want a pure regex solution this can only be done with a variable-width lookbehind pattern, which is supported by only a few regex engines:



                    (?<!(?<!:):(?!:).*).


                    Demo: https://regex101.com/r/Crq49C/2



                    Or if there is always going to be a colon, you can use a positive lookahead pattern instead:



                    .(?=.*(?<!:):(?!:))


                    Demo: https://regex101.com/r/Crq49C/3







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Mar 7 at 21:34

























                    answered Mar 7 at 21:29









                    blhsingblhsing

                    41.6k41743




                    41.6k41743























                        0














                        To just anchor on a single . and not stop until seeing exactly one : I think
                        [.](?=.*:1)
                        will work.
                        This does not work if there is more than one : on a line.






                        share|improve this answer



























                          0














                          To just anchor on a single . and not stop until seeing exactly one : I think
                          [.](?=.*:1)
                          will work.
                          This does not work if there is more than one : on a line.






                          share|improve this answer

























                            0












                            0








                            0







                            To just anchor on a single . and not stop until seeing exactly one : I think
                            [.](?=.*:1)
                            will work.
                            This does not work if there is more than one : on a line.






                            share|improve this answer













                            To just anchor on a single . and not stop until seeing exactly one : I think
                            [.](?=.*:1)
                            will work.
                            This does not work if there is more than one : on a line.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 7 at 21:33









                            Mischa MichaelMischa Michael

                            263




                            263





















                                0














                                You can capture the entire string up until the single : with a simple character set match:



                                [w. :]+(?::1)



                                Then do a replace on all of the .'s in the captured string.



                                Demo: https://regex101.com/r/xDfstu/1






                                share|improve this answer





























                                  0














                                  You can capture the entire string up until the single : with a simple character set match:



                                  [w. :]+(?::1)



                                  Then do a replace on all of the .'s in the captured string.



                                  Demo: https://regex101.com/r/xDfstu/1






                                  share|improve this answer



























                                    0












                                    0








                                    0







                                    You can capture the entire string up until the single : with a simple character set match:



                                    [w. :]+(?::1)



                                    Then do a replace on all of the .'s in the captured string.



                                    Demo: https://regex101.com/r/xDfstu/1






                                    share|improve this answer















                                    You can capture the entire string up until the single : with a simple character set match:



                                    [w. :]+(?::1)



                                    Then do a replace on all of the .'s in the captured string.



                                    Demo: https://regex101.com/r/xDfstu/1







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Mar 7 at 21:36

























                                    answered Mar 7 at 21:26









                                    ChrisChris

                                    1,794419




                                    1,794419



























                                        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%2f55052961%2fmatch-each-occurrence-of-a-dot-until-a-single-colon%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

                                        1928 у кіно

                                        Захаров Федір Захарович

                                        Ель Греко