Regex Escaping Issues

Users discuss problems escaping special characters like backslashes, asterisks, and regex metacharacters in Hacker News comments, often due to markdown rendering for italics and code blocks, while solving regex puzzles or sharing patterns.

📉 Falling 0.3x Programming Languages
2,928
Comments
20
Years Active
5
Top Authors
#4679
Topic ID

Activity Over Time

2007
8
2008
23
2009
50
2010
75
2011
95
2012
99
2013
244
2014
178
2015
138
2016
168
2017
161
2018
145
2019
149
2020
208
2021
257
2022
262
2023
250
2024
240
2025
164
2026
14

Keywords

e.g archive.com LLM HN JS OK formilux.org alternation.html RHH expressions.mobi nix regex match escape want say string sh matches literal character

Sample Comments

petdance • Nov 6, 2013 • View on HN

Learn this one weird trick to match a backslash!

vilya • Dec 10, 2011 • View on HN

Character classes would trip you up, I think. e.g. \w for word characters.

samwillis • Jun 29, 2023 • View on HN

They probably need to replace /^[\d\w!@#$%^&*-]$/i with /[^\w\d]/g.

mhitza • Jul 9, 2022 • View on HN

That regex doesn't do what the description above it says, with or without a backslash.

jandrese • Aug 7, 2019 • View on HN

Isn't this what the /s flag is for in your regex? Assuming you are also using /x of course.

mikorym • Nov 1, 2019 • View on HN

Wow, forgot about the \asterisk being a reserved character.

jey • Apr 16, 2007 • View on HN

Feature request: a way to escape an asterisk. Sometimes you do want to write a literal asterisk. (E.g. to say "a times b")

klyrs • Dec 12, 2021 • View on HN

At least use a backslash... escape the asterisk and you get sh*t not sht sht.

Bother - forgot that asterisks have a special meaning. Sorry about the formatting.

eru • May 14, 2010 • View on HN

Did you try to escape your ^ like \^?