Question/Bug: how do I preserve dashes and not replace them with separator?
See original GitHub issueI am trying to slugify a string, replacing non-matching characters with an underscore, but I don’t want to consider a dash a non-matching character. This is easily achieved with regex but it looks like there is some special slugify behaviour when it comes to dashes which is preventing this working. I can’t see anything in the docs or code, about how to work around this.
What did I do?
slugify.slugify("test-foo bar", separator='_', regex_pattern=r'[^-a-zA-Z0-9_]+')
What happened?
test_foo_bar
What did I expect?
test-foo_bar
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Replace spaces with dashes and make all letters lower-case
I want to convert it to "sonic-free-games" . So whitespaces should be replaced by dashes and all letters converted to small letters. Any...
Read more >awk - Bash - remove dashes and new-lines before replacing ...
Remove dashes used for hyphenation at the end of lines (joining hyphenated lines with the next line in the process) ...
Read more >The Hyphen and the Dash - University of Sussex
That's all there is to know about the dash. Use the dash carefully: overuse of dashes will give your writing a breathless and...
Read more >Convert Text to Table: Cannot Enter a Dash in Options Box
I figured out how to find & replace the dashes with tabs. So, I replace the ( - ) instances with tabs. I...
Read more >Program to replace every space in a string with hyphen
If the character is a space, replace it with the hyphen '-'. Below is the implementation of the above approach:.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@PradeepTammali workaround is something like this:
@PradeepTammali Slugify needs one reserved character, and since the name of the package is
slugify
its job is to convert some random text to adash
-delimited clean text for use in URLs. With that said, the delimiter can also be changed to whatever user wants. In short, theask
here is not doable. I encourage channelling one’s energy to raising a meaningful PR instead.