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?
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
add a comment |
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
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
add a comment |
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
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
python regex python-3.x
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
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
add a comment |
How about the following:
(?:filename=)([^.]*).(w*)
This REGEX returns different groups containing the different elements you're interested in.
add a comment |
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.*)[.]
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
edited Mar 8 at 8:20
answered Mar 8 at 8:12
Michał TurczynMichał Turczyn
15.5k132241
15.5k132241
add a comment |
add a comment |
How about the following:
(?:filename=)([^.]*).(w*)
This REGEX returns different groups containing the different elements you're interested in.
add a comment |
How about the following:
(?:filename=)([^.]*).(w*)
This REGEX returns different groups containing the different elements you're interested in.
add a comment |
How about the following:
(?:filename=)([^.]*).(w*)
This REGEX returns different groups containing the different elements you're interested in.
How about the following:
(?:filename=)([^.]*).(w*)
This REGEX returns different groups containing the different elements you're interested in.
answered Mar 8 at 7:15
![](https://i.stack.imgur.com/Zdo0c.jpg?s=32&g=1)
![](https://i.stack.imgur.com/Zdo0c.jpg?s=32&g=1)
tk78tk78
547310
547310
add a comment |
add a comment |
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.*)[.]
add a comment |
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.*)[.]
add a comment |
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.*)[.]
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.*)[.]
answered Mar 8 at 7:26
YusufsnYusufsn
392215
392215
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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