How to rewrite the [a-zA-Z0-9!$* \t\r\n] pattern to match hyphen along with the existing characters ?
The hyphen is usually a normal character in regular expressions. Only if it’s in a character class and between two other characters does it take a special meaning.
Thus:
[-] matches a hyphen.
[abc-] matches a, b, c or a hyphen.
[-abc] matches a, b, c or a hyphen.
[ab-d] matches a, b, c or d (only here the hyphen denotes a character range).
Escape the hyphen.
[a-zA-Z0-9!$* \t\r\n\-]
UPDATE:
Never mind this answer - you can add the hyphen to the group but you don't have to escape it. See Konrad Rudolph's answer instead which does a much better job of answering and explains why.
It’s less confusing to always use an escaped hyphen, so that it doesn't have to be positionally dependent. That’s a \- inside the bracketed character class.
But there’s something else to consider. Some of those enumerated characters should possibly be written differently. In some circumstances, they definitely should.
This comparison of regex flavors says that C♯ can use some of the simpler Unicode properties. If you’re dealing with Unicode, you should probably use the general category \p{L} for all possible letters, and maybe \p{Nd} for decimal numbers. Also, if you want to accomodate all that dash punctuation, not just HYPHEN-MINUS, you should use the \p{Pd} property. You might also want to write that sequence of whitespace characters simply as \s, assuming that’s not too general for you.
All together, that works out to apattern of [\p{L}\p{Nd}\p{Pd}!$*] to match any one character from that set.
I’d likely use that anyway, even if I didn’t plan on dealing with the full Unicode set, because it’s a good habit to get into, and because these things often grow beyond their original parameters. Now when you lift it to use in other code, it will still work correctly. If you hard‐code all the characters, it won’t.
[-a-z0-9]+,[a-z0-9-]+,[a-z-0-9]+ and also [a-z-0-9]+ all are same.The hyphen between two ranges considered as a symbol.And also [a-z0-9-+()]+ this regex allow hyphen.
use "\p{Pd}" without quotes to match any type of hyphen. The '-' character is just one type of hyphen which also happens to be a special character in Regex.
Is this what you are after?
MatchCollection matches = Regex.Matches(mystring, "-");
Is it possible to use a Multiset for the purpose of counting letter frequencies of the first letter in a word. Those words exist in a list.
example. [the, quick, brown, fox, jumped, over, the, lazy, dog]
Output: most common first character: [t, q, b, f, j, o, l, d]
Output: Most common first character ignoring word frequency: [t]
I just started researching how to use guava solutions.
You'd just need to create a Multiset<Character>, then iterate over the words and add their first character to your multiset (note: there are i18n issues with this, as a general thing). You could either keep track of the most common character as you go or iterate over the multiset later to get it.
Is there a way to change the name of a gist (github) ?, apparently it is ordering the files of the gist in alphabetical order, an naming the gist according to the file that appears first.
Even better, you can add a file with a leading space in its name. It's virtually invisible and gives you more freedom when choosing the title and names for the files:
Considering the order of files within a gist is asciibetical, you can try and add one file in uppercase.
That file will come before any other and will define the name of your gist.
Note that it won't change the url of said gist, as explained in "Namespaced Gists".
Currently, there's no way rename a Github gist. There's been an open issue on this. I would suggest you add a text file to your gist. The file name should start with space ( ), a hash sign (#), an exclamation mark (!), a dollar sign ($) or an ampersand (&). You can add a long description to the body.
For example, naming your file #Github Tricks will change your gist title to #Github Tricks. This will also work if your file name starts with a space ( ) like Github Tricks. If both files exist, the title starting with space takes precedence.
The file names in your gist determine the gist title. The order is listed below.
\t, \n, \x0b, \x0c, \r, , !, ", #, $, %, &, \', (, ), *, +, ,, -, ., /, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, :, ;, <, =, >, ?, #, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, [, \\, ], ^, _, `, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, {, |, }, ~
What I do is creating a first file with leading underscore example : '_simple gist.md' and set it's type as markdown so it also serves as description of my gist .. after reading this post, I will prefix a leading space.
An even better way is to use an ! (exclamation) in front of the name of the file that you always want to be the first in the order. That way you avoid having to add a space everytime you edit the file, as well as adding a tilde ~ to all the remaining files which can be an arbitrary long list.
If you edit the Gist an input box with the filename appears. That can be used to change the filename.
My gist contained a .gitignore which sorts above a leading underscore. I ending up using two leading periods: ..FutureProcessorWithShinyExample.md
I need to convert → (&rarr) to a symbol I can type into a ANSI VBScript file. I am writing a script that translates a select set of htmlcodes to their actual double byte symbols using a regex. Many languages accomplish this using "\0x8594;"... what is the equivelent in VBScript?
Answer was ChrW(8594)
ChrW(&H8594)
Note: Bob King's answer is correct for the information given. The problem is that alumb is mistaken about the meaning of a numeric character entity reference. → (→ single right arrow) is, as stated, also identified as → but this is decimal and so is not equivalent to \x8594 in "many languages" (e.g. C++). This is why chrW(&H8594) gave the "wrong" character. Hexadecimal character entity references are specified using "&#x" instead of "&#". Thus 薔 (薔) = \x8594 = chrW(&H8594) while → (→) = chrW(8594) = \x2192.