Filename match with Python regexCalling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Regular expression to match a line that doesn't contain a word?How to get the current time in PythonRegEx match open tags except XHTML self-contained tagsDoes Python have a string 'contains' substring method?

Ridge Regression with Gradient Descent Converges to OLS estimates

Is camera lens focus an exact point or a range?

Is it improper etiquette to ask your opponent what his/her rating is before the game?

Should I stop contributing to retirement accounts?

Will adding a BY-SA image to a blog post make the entire post BY-SA?

What does the Rambam mean when he says that the planets have souls?

Is it possible to have a strip of cold climate in the middle of a planet?

What does this horizontal bar at the first measure mean?

How much character growth crosses the line into breaking the character

Global amount of publications over time

Can somebody explain Brexit in a few child-proof sentences?

If a character with the Alert feat rolls a crit fail on their Perception check, are they surprised?

Journal losing indexing services

Varistor? Purpose and principle

Does having a TSA Pre-Check member in your flight reservation increase the chances that everyone gets Pre-Check?

We have a love-hate relationship

When quoting, must I also copy hyphens used to divide words that continue on the next line?

Is it possible to use .desktop files to open local pdf files on specific pages with a browser?

Is there a conventional notation or name for the slip angle?

On a tidally locked planet, would time be quantized?

Can I Retrieve Email Addresses from BCC?

Melting point of aspirin, contradicting sources

Is a model fitted to data or is data fitted to a model?

Can the Supreme Court overturn an impeachment?



Filename match with Python regex


Calling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Regular expression to match a line that doesn't contain a word?How to get the current time in PythonRegEx match open tags except XHTML self-contained tagsDoes Python have a string 'contains' substring method?













-1















I have a text file scrapped from my email which contains 1 attachment/mail. The attachment is present under different names with totally different formats, ex.:



filename="John_wheeler 11041997 resume.pdf";
filename="Kujal_newResume(1).pdf";
filename=JohnKrasinski_Resume.pdf


My question is: is there any way to find a RegEx pattern that would start searching from filename= and go until the dot character (that separates from file extension)? Getting file extension would be next task, but I can hold that for now. Please help me figure this out.










share|improve this question



















  • 1





    Your question is unclear. Please provide the data/input you have, the code that you have tried, the expected output and the error you got.

    – Yusufsn
    Mar 8 at 7:13
















-1















I have a text file scrapped from my email which contains 1 attachment/mail. The attachment is present under different names with totally different formats, ex.:



filename="John_wheeler 11041997 resume.pdf";
filename="Kujal_newResume(1).pdf";
filename=JohnKrasinski_Resume.pdf


My question is: is there any way to find a RegEx pattern that would start searching from filename= and go until the dot character (that separates from file extension)? Getting file extension would be next task, but I can hold that for now. Please help me figure this out.










share|improve this question



















  • 1





    Your question is unclear. Please provide the data/input you have, the code that you have tried, the expected output and the error you got.

    – Yusufsn
    Mar 8 at 7:13














-1












-1








-1








I have a text file scrapped from my email which contains 1 attachment/mail. The attachment is present under different names with totally different formats, ex.:



filename="John_wheeler 11041997 resume.pdf";
filename="Kujal_newResume(1).pdf";
filename=JohnKrasinski_Resume.pdf


My question is: is there any way to find a RegEx pattern that would start searching from filename= and go until the dot character (that separates from file extension)? Getting file extension would be next task, but I can hold that for now. Please help me figure this out.










share|improve this question
















I have a text file scrapped from my email which contains 1 attachment/mail. The attachment is present under different names with totally different formats, ex.:



filename="John_wheeler 11041997 resume.pdf";
filename="Kujal_newResume(1).pdf";
filename=JohnKrasinski_Resume.pdf


My question is: is there any way to find a RegEx pattern that would start searching from filename= and go until the dot character (that separates from file extension)? Getting file extension would be next task, but I can hold that for now. Please help me figure this out.







python regex python-3.x






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 8:13









Michał Turczyn

15.5k132241




15.5k132241










asked Mar 8 at 7:07









Srinath RadhakrishnanSrinath Radhakrishnan

42




42







  • 1





    Your question is unclear. Please provide the data/input you have, the code that you have tried, the expected output and the error you got.

    – Yusufsn
    Mar 8 at 7:13













  • 1





    Your question is unclear. Please provide the data/input you have, the code that you have tried, the expected output and the error you got.

    – Yusufsn
    Mar 8 at 7:13








1




1





Your question is unclear. Please provide the data/input you have, the code that you have tried, the expected output and the error you got.

– Yusufsn
Mar 8 at 7:13






Your question is unclear. Please provide the data/input you have, the code that you have tried, the expected output and the error you got.

– Yusufsn
Mar 8 at 7:13













3 Answers
3






active

oldest

votes


















1














You could try this pattern: filename="?([^.]+)



It assumes that dot separates filename from extension.



Explanation:



filename="? - match filename= literally and tehn match 0 or 1 apostrophe "



([^.]+) - match one or more characters that is not a dot (match everything until dot) and store it in capturing group



Your desired filename will be stored in capturing group.



Demo



EXTRA: to capture also file extension, you could use such pattern: filename="?([^.]+).([^";]+)



Additional thing here is .([^";]+): matches dot literally with .. Then it matches one or more characters other than " or ; with pattern [^";]+ and stores it in second capturing gropup.



Another demo






share|improve this answer
































    0














    How about the following:



    (?:filename=)([^.]*).(w*)


    This REGEX returns different groups containing the different elements you're interested in.






    share|improve this answer






























      0














      I'm not sure the output you expect. But this may help. RegexDemo



      (?<=filename=)["]?(w.*[.].*)(?<=w)["]?


      Or if you want to ignore the file extension:



      (?<=filename=)["]?(w.*)[.]





      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%2f55058331%2ffilename-match-with-python-regex%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














        You could try this pattern: filename="?([^.]+)



        It assumes that dot separates filename from extension.



        Explanation:



        filename="? - match filename= literally and tehn match 0 or 1 apostrophe "



        ([^.]+) - match one or more characters that is not a dot (match everything until dot) and store it in capturing group



        Your desired filename will be stored in capturing group.



        Demo



        EXTRA: to capture also file extension, you could use such pattern: filename="?([^.]+).([^";]+)



        Additional thing here is .([^";]+): matches dot literally with .. Then it matches one or more characters other than " or ; with pattern [^";]+ and stores it in second capturing gropup.



        Another demo






        share|improve this answer





























          1














          You could try this pattern: filename="?([^.]+)



          It assumes that dot separates filename from extension.



          Explanation:



          filename="? - match filename= literally and tehn match 0 or 1 apostrophe "



          ([^.]+) - match one or more characters that is not a dot (match everything until dot) and store it in capturing group



          Your desired filename will be stored in capturing group.



          Demo



          EXTRA: to capture also file extension, you could use such pattern: filename="?([^.]+).([^";]+)



          Additional thing here is .([^";]+): matches dot literally with .. Then it matches one or more characters other than " or ; with pattern [^";]+ and stores it in second capturing gropup.



          Another demo






          share|improve this answer



























            1












            1








            1







            You could try this pattern: filename="?([^.]+)



            It assumes that dot separates filename from extension.



            Explanation:



            filename="? - match filename= literally and tehn match 0 or 1 apostrophe "



            ([^.]+) - match one or more characters that is not a dot (match everything until dot) and store it in capturing group



            Your desired filename will be stored in capturing group.



            Demo



            EXTRA: to capture also file extension, you could use such pattern: filename="?([^.]+).([^";]+)



            Additional thing here is .([^";]+): matches dot literally with .. Then it matches one or more characters other than " or ; with pattern [^";]+ and stores it in second capturing gropup.



            Another demo






            share|improve this answer















            You could try this pattern: filename="?([^.]+)



            It assumes that dot separates filename from extension.



            Explanation:



            filename="? - match filename= literally and tehn match 0 or 1 apostrophe "



            ([^.]+) - match one or more characters that is not a dot (match everything until dot) and store it in capturing group



            Your desired filename will be stored in capturing group.



            Demo



            EXTRA: to capture also file extension, you could use such pattern: filename="?([^.]+).([^";]+)



            Additional thing here is .([^";]+): matches dot literally with .. Then it matches one or more characters other than " or ; with pattern [^";]+ and stores it in second capturing gropup.



            Another demo







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 8 at 8:20

























            answered Mar 8 at 8:12









            Michał TurczynMichał Turczyn

            15.5k132241




            15.5k132241























                0














                How about the following:



                (?:filename=)([^.]*).(w*)


                This REGEX returns different groups containing the different elements you're interested in.






                share|improve this answer



























                  0














                  How about the following:



                  (?:filename=)([^.]*).(w*)


                  This REGEX returns different groups containing the different elements you're interested in.






                  share|improve this answer

























                    0












                    0








                    0







                    How about the following:



                    (?:filename=)([^.]*).(w*)


                    This REGEX returns different groups containing the different elements you're interested in.






                    share|improve this answer













                    How about the following:



                    (?:filename=)([^.]*).(w*)


                    This REGEX returns different groups containing the different elements you're interested in.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 8 at 7:15









                    tk78tk78

                    547310




                    547310





















                        0














                        I'm not sure the output you expect. But this may help. RegexDemo



                        (?<=filename=)["]?(w.*[.].*)(?<=w)["]?


                        Or if you want to ignore the file extension:



                        (?<=filename=)["]?(w.*)[.]





                        share|improve this answer



























                          0














                          I'm not sure the output you expect. But this may help. RegexDemo



                          (?<=filename=)["]?(w.*[.].*)(?<=w)["]?


                          Or if you want to ignore the file extension:



                          (?<=filename=)["]?(w.*)[.]





                          share|improve this answer

























                            0












                            0








                            0







                            I'm not sure the output you expect. But this may help. RegexDemo



                            (?<=filename=)["]?(w.*[.].*)(?<=w)["]?


                            Or if you want to ignore the file extension:



                            (?<=filename=)["]?(w.*)[.]





                            share|improve this answer













                            I'm not sure the output you expect. But this may help. RegexDemo



                            (?<=filename=)["]?(w.*[.].*)(?<=w)["]?


                            Or if you want to ignore the file extension:



                            (?<=filename=)["]?(w.*)[.]






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 8 at 7:26









                            YusufsnYusufsn

                            392215




                            392215



























                                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%2f55058331%2ffilename-match-with-python-regex%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

                                Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

                                Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                                2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived