Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Comments on Can I enter raw strings in fish to avoid escaping regexes for sed?

Post

Can I enter raw strings in fish to avoid escaping regexes for sed?

+4
−0

When running sed through fish, I often encounter a problem with regexes. Many commonly used regex control characters like []{}().+ need to be escaped, even if I type the regex in a single quoted string. For example:

$ echo abc | sed 's/b+/X/'
abc

$ echo abc | sed 's/b\+/X/'
aXc

This constant \ in front of many characters makes my regexes absolutely unreadable. It gets even worse if the regex itself needs to escape characters, the whole thing becomes a jumble of backslashes.

Surely there's a better way to enter complex strings in the shell? I don't know if this is a fish problem, or a generic shell problem, or a sed problem, but I would love to know how to avoid it.

As an example of what I expect: Python has an elegant solution to this, called "raw strings". r"b+" is therefore interpreted without any formatting or templating at all. Is there a raw string option in fish, or other shells? Does sed have an alternate input mode to get around this annoying problem?

History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Regarding new tag (2 comments)
Regarding new tag
matthewsnyder‭ wrote 11 months ago

I decided to create the tag quotes for this, to represent question to do with escaping strings in shells. I think it's a more direct and obvious term than escaping for example. Anyhow, I'd love to add a description to the tag, but I couldn't figure out how to do it.

AdminBee‭ wrote 11 months ago

As for adding a tag description: this help page explains that to earn this ability you need a minimum of 76 approved edit suggestions. If I read your user profile correctly, you only have 11 edits so far, so this is likely the reason you can't (yet).