9

Regex to match everything between # and punctuation characters

 2 years ago
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

advertisements

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

Debuggex Demo


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}}

What reg expression patten to I need to match everything between {{ and }} I'm trying to parse wikipedia, but im ending up with orphan }} after running the rexex code. Here's my PHP script. <?php $articleName='england'; $url = "http://en.wikipedia

Regex to match everything between a string and a caret (^) excluding the occurrence of caret (^)

Here is the data [StupidHtml]: AZaz.-09^abcdabcd^a^a^ I need a regex to retrieve data between [StupidHtml]: and first occurrence of ^ Currently I am using (?<=\[StupidHtml\]\:)(.*)(?=\^) But that results in: AZaz.-09^abcdabcd^a^a I need to achieve Az

How to create a regex to match everything inside and including & lt; div & gt; & hellip; & lt; / div & gt;?

This is the sample text that I'm working with. I'm using Coda to do a find and replace... <td width="20%"><div > Item #</div></td> <td width="20%"><div > Pole Tip</div></td> <td width=

Regex and javascript: match everything between the number followed by the space and by uppercase letter

I am trying to write a regular expression to be used with javascript. This regex should be able to match everything between number + space + capital letter. Here is an example: var string = testtesttesttesttest1 This shuld be matched2 This shuld also

RegEx to select everything between two characters?

I am trying to write a regex that selects everything between two characters. For example, when the regex encounters a '§' I want it to select everything after the '§' sign, up until the point that the regex encounters a ';'. I tried with a lookbehind

Regex to match everything except the name and extension of the image

I have this regex ((?:https?\:\/\/)(?:[a-zA-Z]{1}(?:[\w\-]+\.)+(?:[\w]{2,5}))(?:\:[\d]{1,5})?\/(?:[^\s\/]+\/)*(?:[^\s]+\.(?:png|jpe?g|gif|svg|PNG|JPE?G|GIF|SVG))(?:\?\w+=\w+(?:&\w+=\w+)*)?) to select these image urls from a string http://my.a.example

Regex that matches everything before an underscore

I have a fair bit of Regex knowledge, but I'm stumped by this one. I need a Regex that matches everything before the last underscore, but only if the text after the underscore is "self", "ally" or "enemy". So if I have input

The complex regex matches everything between a set of characters?

Regex! This isn't for a specific language. It's for a multi-file renamer that lets you use regex. So I'm just looking for a "pure" regex solution. I'm having trouble finding an answer that fits so I figured I'd ask. Here is an example of the kin

Regex to match text longer than x characters between html tags?

I have the task of migrating THE worst HTML product descriptions you will ever encounter. It consists of a mixture of tables and paragraphs. The majority are not even 100% valid HTML and there are plenty of Microsoft tags courtesy of MS Word. It is l

Regex to match everything except a list of characters

I want to match a line containing everything except the specified characters [I|V|X|M|C|D|L]. new Regex(@"^(.*) is (?![I|V|X|M|C|D|L].*)$") should match everything except the characters mentioned in the OR list. Should match - name is a Should n

regex to find everything between & lt; a & gt; and & lt; / a & gt; Keywords

I'm trying to find a way to make a list of everything between <a> and </a> tags. So I have a list of links and I want to get the names of the links (not where the links go, but what they're called on the page). Would be really helpful to me. C

Regex between and including characters on multiple lines

I have the below text: BEGIN: >>DocTypeName: Zoning Letter >>DocDate: 4/16/2014 Loan Number: 355211 Ad Hoc: ZONING VERIFICATION LETTER Document Handle: 712826 >>DiskgroupNum: 102 >>VolumeNum: 367 >>NumOfPages: 0 >>FileS

Regex to match a word and everything after?

I need to dump some http data as a string from the http packet which i have in string format am trying to use the regular expression below to match 'data:'and everything after it,Its not working . I am new to regex and python >>>import re >>

POSIX regex to find everything between word and word

I have string as: FOO /some/%string-in.here BAR I would like to get everything between FOO and BAR but NOT including FOO[:space:] and NOT including [:space:]BAR Any ideas it will be appreciate it.Can't you just use a capturing group? /FOO (.+?) BAR/

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK