Regex catch from the hash sign "#" to the next white space

regex tester
regex cheat sheet
ruby regex
regex dot character
regex forward slash
regex backslash
regular expression dollar sign
regex period escape

I have a script line this :

#type1 this is the text of the note

I've tried this bu didn't workout for me :


I watch to catch type in other words I to get whats between the hash sign "#" and the next white space, excluding the hash "#" sign, and the string that I want to catch is alphanumeric string.

With the regex functionality provided by Javascript:

exec_result = /#(\w*)/.exec('#whatever string comes here');

I believe exec_result[1] should be the string you want.

The return value of exec() method could be found over here:

Hashtag RegEx, Url Validation Regex | Regular Expression - Taha � Match or Validate phone number � match whole word � nginx test � Extract String Between Two STRINGS Well, no: this positive lookbehind requires a hash character—whereas we also want to allow the absence of any character on the left. The negative lookahead at the end of the string follows the same principle: (?![^#]) asserts that what follows is not a character that is not a hash—i.e., if it is a character, it must be a hash. Limitation

You're really close:


The \w matches any letters or numbers (and underscores too). And the space should be outside the matching group since I guess you don't want to capture it.

How to escape # hash character in regex match strings, I've tried to escape the hash symbol in the match string without result. Any ideas? Is the answer something I overlooked in my lurching Python Within a regular expression, special characters such as tab and newline can be escaped with either an accent (`) or a backslash (\). For example, `t is the same as \t except when the x option is used. To learn the basics of regular expressions (or refresh your memory of pattern syntax), see the RegEx Quick Reference.

To get an alphanumeric match (which will get you type1), instead of the negated character class [^\s] which matches not a whitespace character, you could use a character class and specify what you want to match like [A-Za-z0-9].

Then use a negative lookahead to assert what is on the right is not a non-whitespace char:


Regex demo

Your match is in the first capturing group. Note that you don't have to escape the \#

For example using the case insensitive flag /i

const regex = /^#([A-Za-z0-9]+)(?!\S)/i;
const str = `#type1 this is the text of the note`;

Class: Regexp (Ruby 2.7.1), A Regexp holds a regular expression, used to match a pattern against strings. A character class is delimited with square brackets ( [ , ] ) and lists characters that may /[[:xdigit:]]/ - Digit allowed in a hexadecimal number (i.e., 0-9a-fA-F). [0-9]% a string that has a character from 0 to 9 before a % sign [^a-zA-Z] a string that has not a letter from a to z or from A to Z. In this case the ^ is used as negation of the expression

I've figured it out.


Dot (.) and backslash (\) - Analytics Help, is used to separate the whole part of a number from the fractional part. Regular expressions first evaluates a special character in the context of regular expressions: if it sees a dot, then it knows to match any one character. For example, the� You could use a look-ahead assertion: (?!999)\d{3} This example matches three digits other than 999. But if you happen not to have a regular expression implementation with this feature (see Comparison of Regular Expression Flavors), you probably have to build a regular expression with the basic features on your own.

regular expressions, Regular expressions are strings that can be recognized by a regular grammar, In this example, the pound sign (#) becomes the delimiter. And, of everything in the string up to the match; and $', everything in the string beyond the match. Unless you have to, don't try to match beyond the criteria. If it's still slow, you might want break down the hash a bit more, eg by creating a hash of hashes, where the keys of the first hash are the digits left of the comma.

Simple RegEx Tutorial, a string that starts and ends with "abc" - effectively an exact match comparison. In addition, the symbols '*', '+', and '?', denote the number of times a character or for instance, the regular expression "(\$|A)[0-9]+" would have the function call:� RegexOptions.IgnorePatternWhitespace - Eliminates unescaped white space from the pattern and enables comments marked with the hash sign (#). RegexOptions.Compiled - Specifies that the regular expression is compiled to an assembly. The regular expression will be faster to match but it takes more time to compile initially.

about_Regular_Expressions, This article demonstrates regular expression syntax in PowerShell. [character group] allows you to match any number of characters one time,� identifier shouldn't contain that hash character. The correct pattern should be 'A1234509', but is instead often merely entered as '#12345' when the first character, representing an alphabet sequence for the month, and the last two characters, representing a two-digit year, can be assumed. Identifying the hash character in a RegEx match is a way

  • Okay, and where's your attempt? We can help you fix it, but we're not gonna write it for you (unless you hire us ;) )
  • @NiettheDarkAbsol I've aded the attempt that I've made
  • Why is the expected ouptut type and not type1 considering you want to capture everything between # and the next space? Your code should work as it is:
  • @RahmaniSeifelmoulouk Did any of the provided answers help you solve the problem? Please see someone answers.