Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

LOL you're right! I just pasted the template here, but my defaults are equivalent to plain old `?`. I don't use the match if `?` would work.


sort by: page size:

You want the "?" operator.

It has to be '?.(...)' not '?(...)', because '?(...)' is already part of valid syntax. For example "this.myOptionalfunction?('hello'):('goodbye')".

Good to know, thanks.

I'd argue that perl gets it right--as the default behavior, this behavior would gravely violate the principle of least surprise, but for the 0.01% of people who want \d to match ?, there's no harm to making it available as an option you need to specifically request.


If you're capturing something you don't want, you can always prefix your match with '?:' to have a non-capturing group.

FWIW, I personally prefer the #match method. Some of the examples in this article just make me want to hurt people. Especially usage of $1, $2, etc.


You can write "lambda" instead of ?. DrRacket also has a shortcut to insert ? easily.

How do I write "??"? I can only write "?"

I started using ? as the leader (I don't do reverse searches). The other options (, \) always get in the way while programming. I might try the backtick, but it means that programming in languages that use backticks (Rust, I think) would be a pain.

No, it doesn't. Using a '?' will cause a syntax error.

That's awful. Can you have "<=" = "=" and "<=" = "?" but "=" ? "?"?

Appending just the question mark works here.

In fact quite a lot of commands also respond to -?, which is my guess for what inspired this.

Either way, even an extremely imperfectly honoured convention is better than no convention at all.


How is the ? used?

>> ? vs ?

Also ? looks similar.


I'm using ? and ? for that.

Any query string works. So, "?s=1" or "?x=1" for instance. If you're feeling lazy.

But doesn't << /fred.md >> beat the heck out of something like << /fred?format=md >>?

Not quite. This works:

     (?:(?!>).)*>?
But that is a very long winded way of writing:

     [^>]*?>
which is long way of writing:

     [^>]*>

For what it's worth, I like to use backticks in these situations (e.g. `h?`). I think it reduces ambiguity a bit.

Oh good, we can just use ? for everything now. Much simpler.
next

Legal | privacy