Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Matching [] characters with regex #18612
Comments
|
Some info: The single quotes tell the shell to not scan and potentially mangle the string, so you should always use it when you can. That way you also introduce some additional speed to the processing. Use
You're doing the brackets correctly since you're escaping them. |
|
@rautamiekka I changed the pattern to this: (?:\[(?P<genre>.+?)\] - )?(?P<artist>.+?) - (?P<track>.+?)(?: \[[\w ]+\])?Are you sure I'm doing the Maybe |
|
Invalid regex. Must be something like |
|
Final regex is this: (?:\[(?P<genre>.+?)\]\s*-\s*)?(?P<artist>.+?)\s*-\s*(?P<track>.+?)(?:\s*\[|$)Works on all the tests I could find. I thought the regex had to match the whole title but apparently not. We can just find the I'm really happy with this! Thank you for your help! |
Please follow the guide below
xinto all the boxes [ ] relevant to your issue (like this:[x])Make sure you are using the latest version: run
youtube-dl --versionand ensure your version is 2018.12.17. If it's not, read this FAQ entry and update. Issues with outdated version will be rejected.Before submitting an issue make sure you have:
What is the purpose of your issue?
Description of your issue, suggested solution and other information
Explanation of your issue in arbitrary form goes here. Please make sure the description is worded well enough to be understood. Provide as much context and examples as possible.
If work on your issue requires account credentials please provide them or explain how one can obtain them.
I'm using the
--metadata-from-titleflag with regex and I would like to match the[character. This is the full regex pattern.I'm surrounding the pattern in
'single quotes'in the shell (bash). I'm not sure if I should be using"double quotes". I'm not really familiar with the difference between the two.This URL has a sufficiently complex title for testing (although it doesn't have a multi-word genre).
These are some URLs that I've been testing with.
I would like to match this title. For the first one,
genreshould be set toElectro,artistshould be set toSound Remedy & Nitro Funand thetrackshould be set toTurbo Penguin.[Monstercat Release]should not be included in thetrack.[Electro] -and[Monstercat Release]are optional.This is how the title is parsed with the current regex
The problem I'm having is with the track. The part that is supposed to match anything within
[]seems to be matching some of the track characters. With some variations of the pattern, the track is parsed asTurbobut I can't seem to get it to parse asTurbo Penguin. I think my problem has something to do with[]. Also, I've never used?in regex before. Nor have I used named capture groups (didn't even know they existed).My full
youtube-dlinvokation is this:I'm fiddled around with the regex for a while and I can't seem to figure it out. Maybe
bashoryoutube-dlare doing something funky with[]? I don't know.