How do extract the string before the colon?2019 Community Moderator ElectionHow 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

What is better: yes / no radio, or simple checkbox?

What is Tony Stark injecting into himself in Iron Man 3?

Should I take out a loan for a friend to invest on my behalf?

PTIJ: Why does only a Shor Tam ask at the Seder, and not a Shor Mu'ad?

Windows Server Datacenter Edition - Unlimited Virtual Machines

Is divide-by-zero a security vulnerability?

Is it safe to abruptly remove Arduino power?

Why aren't there more Gauls like Obelix?

Why do we say ‘pairwise disjoint’, rather than ‘disjoint’?

I can't die. Who am I?

What do you call someone who likes to pick fights?

Finitely many repeated replacements

What materials can be used to make a humanoid skin warm?

How many characters using PHB rules does it take to be able to have access to any PHB spell at the start of an adventuring day?

Proving a statement about real numbers

How do electrons receive energy when a body is heated?

Getting the || sign while using Kurier

What is the generally accepted pronunciation of “topoi”?

What ability score modifier does a javelin's damage use?

Are small insurances worth it?

In the late 1940’s to early 1950’s what technology was available that could melt a LOT of ice?

Doesn't allowing a user mode program to access kernel space memory and execute the IN and OUT instructions defeat the purpose of having CPU modes?

For which categories of spectra is there an explicit description of the fibrant objects via lifting properties?

Would an aboleth's Phantasmal Force lair action be affected by Counterspell, Dispel Magic, and/or Slow?



How do extract the string before the colon?



2019 Community Moderator ElectionHow 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_repasfmq


Desired result:



asfmqwdbd/ilcp:dftqclk_rep


My code:



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









share|improve this question









New contributor




Thibhika Ravichandran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • 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_repasfmq


Desired result:



asfmqwdbd/ilcp:dftqclk_rep


My code:



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









share|improve this question









New contributor




Thibhika Ravichandran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • 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_repasfmq


Desired result:



asfmqwdbd/ilcp:dftqclk_rep


My code:



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









share|improve this question









New contributor




Thibhika Ravichandran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












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



Sample input:



asfmqwdbd/ilcp:dftqclk_repasfmq


Desired result:



asfmqwdbd/ilcp:dftqclk_rep


My code:



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






regex perl






share|improve this question









New contributor




Thibhika Ravichandran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Thibhika Ravichandran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Mar 7 at 7:04









ikegami

266k11178401




266k11178401






New contributor




Thibhika Ravichandran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Mar 7 at 5:07









Thibhika RavichandranThibhika Ravichandran

1




1




New contributor




Thibhika Ravichandran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Thibhika Ravichandran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Thibhika Ravichandran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • 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
        );



        );






        Thibhika Ravichandran is a new contributor. Be nice, and check out our Code of Conduct.









        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

            3,76211125




            3,76211125























                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,1982421




                            4,1982421




















                                Thibhika Ravichandran is a new contributor. Be nice, and check out our Code of Conduct.









                                draft saved

                                draft discarded


















                                Thibhika Ravichandran is a new contributor. Be nice, and check out our Code of Conduct.












                                Thibhika Ravichandran is a new contributor. Be nice, and check out our Code of Conduct.











                                Thibhika Ravichandran is a new contributor. Be nice, and check out our Code of Conduct.














                                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

                                Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

                                Posting a File and Associated Data to a RESTful WebService preferably as JSON2019 Community Moderator ElectionREST URI convention - Singular or plural name of resource while creating itUploading both data and files in one form using Ajax?How do I upload a file with metadata using a REST web service?REST API - file (ie images) processing - best practicesSpring: JSON data and file in the same requestREST API Put large dataPosting a file and JSON data to Spring rest serviceRESTful Web Service Upload/Download Large Data With JSONREST API Design sending JSON data and a file to the api in same requestPost JSONArray to REST servicePUT vs. POST in RESTParsing values from a JSON file?JavaScript/jQuery to download file via POST with JSON dataHow do I upload a file with metadata using a REST web service?How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?Separate REST JSON API server and client?what's the correct way to send a file from REST web service to client?How do I write JSON data to a file?What is “406-Not Acceptable Response” in HTTP?REST API - file (ie images) processing - best practices

                                How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page