![](/style/images/good.png)
![](/style/images/bad.png)
Regex to match everything between # and punctuation characters
source link: https://www.codesd.com/item/regex-to-match-everything-between-and-punctuation-characters.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Regex to match everything between # and punctuation characters
I need to extract everything between a #
and a space or any punctation character ( .,;:_-
) This is what I have so far.
var str = "#hello. foo bar"
var filter:RegExp = /#(.*?)(!.,?;:_-)/g;
var matches:Object = filter.exec(str);
if(matches != null){
trace("Found: "+matches[1])
} else {
trace("nothing found")
}
It only works if the word is #hello! - I guess this part (!.,?;:_-)
is wrong?
Regex101
This example will be taking advantage of the [^]
character group, this will match any character that is not in the group. This allows you to simply say any not-in-list character.
#([^[\., -\/#!$%\^&\*;:{}=\-_`~()]+)
![zKb-g6MDNcxfNMfx.png](https://www.debuggex.com/i/zKb-g6MDNcxfNMfx.png)
jsFiddle
var str = "#hello. foo bar";
var filter = RegExp = /#([^[\., -\/#!$%\^&\*;:{}=\-_`~()]+)/g;
var matches = Object = filter.exec(str);
if (matches !== null) {
console.log("Found: " + matches[1]);
} else {
console.log("nothing found");
}
Related Articles
What expression pattern reg to I must match everything between {{and}}
Regex to match everything between a string and a caret (^) excluding the occurrence of caret (^)
How to create a regex to match everything inside and including & lt; div & gt; & hellip; & lt; / div & gt;?
Regex and javascript: match everything between the number followed by the space and by uppercase letter
RegEx to select everything between two characters?
Regex to match everything except the name and extension of the image
Regex that matches everything before an underscore
The complex regex matches everything between a set of characters?
Regex to match text longer than x characters between html tags?
Regex to match everything except a list of characters
regex to find everything between & lt; a & gt; and & lt; / a & gt; Keywords
Regex between and including characters on multiple lines
Regex to match a word and everything after?
POSIX regex to find everything between word and word
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK