Reputation: 3697
It seems that i'm stuck with something simple, but I was unable to find quite similar question on stack.
Using JavaScript/jQuery/regexp
I want to match a words that contains specific symbols in string .
I.e in given string 'check out mydomain/folder/#something'
if i run this kind of search with symbols 'folder/#'
it must return whole mydomain/folder/#something
.
In fact I want to use this to replace whole link in a string with some kind of widget button, but as those links are pretty specific (i.e i know that they will contain folder/#
) using some kind of library for this task would be overkill.
Upvotes: 0
Views: 49
Reputation: 19193
Here is the regexp you are looking for: /[\w\/]*\/folder\/#[\w\/]*/
var str = 'check out mydomain/folder/#something';
// returns ["mydomain/folder/#something"]
str.match(/[\w\/]*\/folder\/#[\w\/]*/)
Or for a more robust version or it: /[\w\/\.]*\/folder\/#(?:[\w\/]|\.\w+)*/
That last one will accept dots in the file names but ignore the last one.
For instance 'check out my.domain/foo/folder/#some.thing.'
will return ["my.domain/foo/folder/#some.thing"]
Upvotes: 1