How do extract the string before the colon?How to validate an email address in JavaScript?How to validate an email address using a regular expression?Regular expression to match a line that doesn't contain a word?How do you access the matched groups in a JavaScript regular expression?How do you use a variable in a regular expression?How do I make the first letter of a string uppercase in JavaScript?How to replace all occurrences of a string in JavaScriptWhat regex will match every character except comma ',' or semi-colon ';'?Python: Extract numbers from a stringHow to extract a substring using regex

How to preserve electronics (computers, iPads and phones) for hundreds of years

Why does this expression simplify as such?

The IT department bottlenecks progress, how should I handle this?

What's the name of the logical fallacy where a debater extends a statement far beyond the original statement to make it true?

Which Article Helped Get Rid of Technobabble in RPGs?

What features enable the Su-25 Frogfoot to operate with such a wide variety of fuels?

I found an audio circuit and I built it just fine, but I find it a bit too quiet. How do I amplify the output so that it is a bit louder?

What is the difference between lands and mana?

Delete multiple columns using awk or sed

PTIJ: Why is Haman obsessed with Bose?

Pre-mixing cryogenic fuels and using only one fuel tank

How to explain what's wrong with this application of the chain rule?

Does the reader need to like the PoV character?

What to do when eye contact makes your coworker uncomfortable?

Mimic lecturing on blackboard, facing audience

When were female captains banned from Starfleet?

15% tax on $7.5k earnings. Is that right?

Why is it that I can sometimes guess the next note?

Doesn't the system of the Supreme Court oppose justice?

Can I cause damage to electrical appliances by unplugging them when they are turned on?

Can you use Vicious Mockery to win an argument or gain favours?

Microchip documentation does not label CAN buss pins on micro controller pinout diagram

How many arrows is an archer expected to fire by the end of the Tyranny of Dragons pair of adventures?

Were Persian-Median kings illiterate?



How do extract the string before the colon?


How to validate an email address in JavaScript?How to validate an email address using a regular expression?Regular expression to match a line that doesn't contain a word?How do you access the matched groups in a JavaScript regular expression?How do you use a variable in a regular expression?How do I make the first letter of a string uppercase in JavaScript?How to replace all occurrences of a string in JavaScriptWhat regex will match every character except comma ',' or semi-colon ';'?Python: Extract numbers from a stringHow to extract a substring using regex













-1















How do extract the string before the colon. I don't want the string after the colon.



Sample input:



asfmqwdbd/ilcp:dftqclk_rep


Desired result:



asfmqwdbd/ilcp


My code:



if (m/^(S+))
$inst_name = $1;









share|improve this question
























  • m/^([^s:]+)/ - if you meant before the first colon

    – Wiktor Stribiżew
    Mar 7 at 6:05












  • Can ypu please edit your question? Your example does not contain a semicolon ;. Did you mean colon :?

    – Stefan Becker
    Mar 7 at 6:06











  • Shouldn't the desired result be asfmqwdbd/ilcp?

    – ikegami
    Mar 7 at 7:04















-1















How do extract the string before the colon. I don't want the string after the colon.



Sample input:



asfmqwdbd/ilcp:dftqclk_rep


Desired result:



asfmqwdbd/ilcp


My code:



if (m/^(S+))
$inst_name = $1;









share|improve this question
























  • m/^([^s:]+)/ - if you meant before the first colon

    – Wiktor Stribiżew
    Mar 7 at 6:05












  • Can ypu please edit your question? Your example does not contain a semicolon ;. Did you mean colon :?

    – Stefan Becker
    Mar 7 at 6:06











  • Shouldn't the desired result be asfmqwdbd/ilcp?

    – ikegami
    Mar 7 at 7:04













-1












-1








-1








How do extract the string before the colon. I don't want the string after the colon.



Sample input:



asfmqwdbd/ilcp:dftqclk_rep


Desired result:



asfmqwdbd/ilcp


My code:



if (m/^(S+))
$inst_name = $1;









share|improve this question
















How do extract the string before the colon. I don't want the string after the colon.



Sample input:



asfmqwdbd/ilcp:dftqclk_rep


Desired result:



asfmqwdbd/ilcp


My code:



if (m/^(S+))
$inst_name = $1;






regex perl






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 12 at 7:47







Thibhika Ravichandran

















asked Mar 7 at 5:07









Thibhika RavichandranThibhika Ravichandran

11




11












  • m/^([^s:]+)/ - if you meant before the first colon

    – Wiktor Stribiżew
    Mar 7 at 6:05












  • Can ypu please edit your question? Your example does not contain a semicolon ;. Did you mean colon :?

    – Stefan Becker
    Mar 7 at 6:06











  • Shouldn't the desired result be asfmqwdbd/ilcp?

    – ikegami
    Mar 7 at 7:04

















  • m/^([^s:]+)/ - if you meant before the first colon

    – Wiktor Stribiżew
    Mar 7 at 6:05












  • Can ypu please edit your question? Your example does not contain a semicolon ;. Did you mean colon :?

    – Stefan Becker
    Mar 7 at 6:06











  • Shouldn't the desired result be asfmqwdbd/ilcp?

    – ikegami
    Mar 7 at 7:04
















m/^([^s:]+)/ - if you meant before the first colon

– Wiktor Stribiżew
Mar 7 at 6:05






m/^([^s:]+)/ - if you meant before the first colon

– Wiktor Stribiżew
Mar 7 at 6:05














Can ypu please edit your question? Your example does not contain a semicolon ;. Did you mean colon :?

– Stefan Becker
Mar 7 at 6:06





Can ypu please edit your question? Your example does not contain a semicolon ;. Did you mean colon :?

– Stefan Becker
Mar 7 at 6:06













Shouldn't the desired result be asfmqwdbd/ilcp?

– ikegami
Mar 7 at 7:04





Shouldn't the desired result be asfmqwdbd/ilcp?

– ikegami
Mar 7 at 7:04












3 Answers
3






active

oldest

votes


















1














Assuming that semicolon (;) was a typo in the question and you actually meant colon (:) this would be the correct regex:



  • anchor at beginning of line (^)

  • capture one-or-more non-colon characters (([^:]+))

  • match must end on a colon (:)

#!/usr/bin/perl
use warnings;
use strict;

while (<DATA>)
print "$1n" if /^([^:]+):/;


exit 0;

__DATA__
asfmqwdbd/ilcp
asfmqwdbd/ilcp:dftqclk_repasfmq
asfmqwdbd/ilcp;dftqclk_repasfmq


Test run:



$ perl dummy.pl
asfmqwdbd/ilcp





share|improve this answer






























    0














    Assuming from your question you want the output like this
    "asfmqwdbd/ilcp"
    for this you can use "^([S]+):" and then use $1.






    share|improve this answer






























      0














      I think you are looking for



      $ echo "asfmqwdbd/ilcp:dftqclk_repasfmq" | perl -pe 's/(S+):.*/$1/ '
      asfmqwdbd/ilcp


      or



      $ perl -le ' $x="asfmqwdbd/ilcp:dftqclk_repasfmq"; $x=~s/(S+):.*/$1/; print $x '
      asfmqwdbd/ilcp

      $





      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%2f55036459%2fhow-do-extract-the-string-before-the-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














        Assuming that semicolon (;) was a typo in the question and you actually meant colon (:) this would be the correct regex:



        • anchor at beginning of line (^)

        • capture one-or-more non-colon characters (([^:]+))

        • match must end on a colon (:)

        #!/usr/bin/perl
        use warnings;
        use strict;

        while (<DATA>)
        print "$1n" if /^([^:]+):/;


        exit 0;

        __DATA__
        asfmqwdbd/ilcp
        asfmqwdbd/ilcp:dftqclk_repasfmq
        asfmqwdbd/ilcp;dftqclk_repasfmq


        Test run:



        $ perl dummy.pl
        asfmqwdbd/ilcp





        share|improve this answer



























          1














          Assuming that semicolon (;) was a typo in the question and you actually meant colon (:) this would be the correct regex:



          • anchor at beginning of line (^)

          • capture one-or-more non-colon characters (([^:]+))

          • match must end on a colon (:)

          #!/usr/bin/perl
          use warnings;
          use strict;

          while (<DATA>)
          print "$1n" if /^([^:]+):/;


          exit 0;

          __DATA__
          asfmqwdbd/ilcp
          asfmqwdbd/ilcp:dftqclk_repasfmq
          asfmqwdbd/ilcp;dftqclk_repasfmq


          Test run:



          $ perl dummy.pl
          asfmqwdbd/ilcp





          share|improve this answer

























            1












            1








            1







            Assuming that semicolon (;) was a typo in the question and you actually meant colon (:) this would be the correct regex:



            • anchor at beginning of line (^)

            • capture one-or-more non-colon characters (([^:]+))

            • match must end on a colon (:)

            #!/usr/bin/perl
            use warnings;
            use strict;

            while (<DATA>)
            print "$1n" if /^([^:]+):/;


            exit 0;

            __DATA__
            asfmqwdbd/ilcp
            asfmqwdbd/ilcp:dftqclk_repasfmq
            asfmqwdbd/ilcp;dftqclk_repasfmq


            Test run:



            $ perl dummy.pl
            asfmqwdbd/ilcp





            share|improve this answer













            Assuming that semicolon (;) was a typo in the question and you actually meant colon (:) this would be the correct regex:



            • anchor at beginning of line (^)

            • capture one-or-more non-colon characters (([^:]+))

            • match must end on a colon (:)

            #!/usr/bin/perl
            use warnings;
            use strict;

            while (<DATA>)
            print "$1n" if /^([^:]+):/;


            exit 0;

            __DATA__
            asfmqwdbd/ilcp
            asfmqwdbd/ilcp:dftqclk_repasfmq
            asfmqwdbd/ilcp;dftqclk_repasfmq


            Test run:



            $ perl dummy.pl
            asfmqwdbd/ilcp






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 7 at 6:11









            Stefan BeckerStefan Becker

            4,11521125




            4,11521125























                0














                Assuming from your question you want the output like this
                "asfmqwdbd/ilcp"
                for this you can use "^([S]+):" and then use $1.






                share|improve this answer



























                  0














                  Assuming from your question you want the output like this
                  "asfmqwdbd/ilcp"
                  for this you can use "^([S]+):" and then use $1.






                  share|improve this answer

























                    0












                    0








                    0







                    Assuming from your question you want the output like this
                    "asfmqwdbd/ilcp"
                    for this you can use "^([S]+):" and then use $1.






                    share|improve this answer













                    Assuming from your question you want the output like this
                    "asfmqwdbd/ilcp"
                    for this you can use "^([S]+):" and then use $1.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 7 at 10:28









                    Huban AhmedHuban Ahmed

                    41




                    41





















                        0














                        I think you are looking for



                        $ echo "asfmqwdbd/ilcp:dftqclk_repasfmq" | perl -pe 's/(S+):.*/$1/ '
                        asfmqwdbd/ilcp


                        or



                        $ perl -le ' $x="asfmqwdbd/ilcp:dftqclk_repasfmq"; $x=~s/(S+):.*/$1/; print $x '
                        asfmqwdbd/ilcp

                        $





                        share|improve this answer



























                          0














                          I think you are looking for



                          $ echo "asfmqwdbd/ilcp:dftqclk_repasfmq" | perl -pe 's/(S+):.*/$1/ '
                          asfmqwdbd/ilcp


                          or



                          $ perl -le ' $x="asfmqwdbd/ilcp:dftqclk_repasfmq"; $x=~s/(S+):.*/$1/; print $x '
                          asfmqwdbd/ilcp

                          $





                          share|improve this answer

























                            0












                            0








                            0







                            I think you are looking for



                            $ echo "asfmqwdbd/ilcp:dftqclk_repasfmq" | perl -pe 's/(S+):.*/$1/ '
                            asfmqwdbd/ilcp


                            or



                            $ perl -le ' $x="asfmqwdbd/ilcp:dftqclk_repasfmq"; $x=~s/(S+):.*/$1/; print $x '
                            asfmqwdbd/ilcp

                            $





                            share|improve this answer













                            I think you are looking for



                            $ echo "asfmqwdbd/ilcp:dftqclk_repasfmq" | perl -pe 's/(S+):.*/$1/ '
                            asfmqwdbd/ilcp


                            or



                            $ perl -le ' $x="asfmqwdbd/ilcp:dftqclk_repasfmq"; $x=~s/(S+):.*/$1/; print $x '
                            asfmqwdbd/ilcp

                            $






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 7 at 17:14









                            stack0114106stack0114106

                            4,7602423




                            4,7602423



























                                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%2f55036459%2fhow-do-extract-the-string-before-the-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

                                Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

                                Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

                                Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved