-1

How do I make a Slash able to be used in this Metachar String:

/@(\w+)\b/gi

That is supposed to find the "Text"(@text) This is a test @Text I agree And it does. But now I wan't the same thing for somthing that uses a /

Mulan
  • 129,518
  • 31
  • 228
  • 259
Kai Gray
  • 1
  • 3
  • wait so includes `@` and a forward slash? – Richard Hamilton Mar 12 '16 at 19:20
  • just escape it, like everything else you need that's otherwise an active character. You use `\/` inside the pattern. Just like how `\.` is a full stop, not "any character", and how `\[` is a square bracket, not a grouping operator. Hit up http://www.regular-expressions.info, too, and read up on how to use regex. The [how to ask a good question](http://stackoverflow.com/help/how-to-ask) article doesn't start with "Search, and research" for nothing =) – Mike 'Pomax' Kamermans Mar 12 '16 at 19:21
  • Is this `/@(\w+)\b/gi` a literal you are trying to find ? Otherwise, I don't see a _Metachar String_ –  Mar 12 '16 at 19:28
  • The only _metacharacters_ in your regex are these (+)\, the forward slashes in your string `/../` are nothing more than a delimiter, like a string delimiter. It's for the language, not the regex engine. Regex engine's don't have or know about delimiters, just metachars. Like any language string, the delimiter has to be escaped in it's contents. –  Mar 12 '16 at 19:46
  • Also, this RVAL form `/../` has special parsing meaning in JS, it converts it's contents into a regex _object_. It's a free-form language enhancement from long ago. New JS lets you be more specific by doing a new RegExp("") object without the `//` delimiters. –  Mar 12 '16 at 19:54

2 Answers2

0

You need to escape the slash so it is not interpreted as denoting special meaning. Escaping means prefixing with a backslash, so you just need two together. Adapting your existing example:

/@([\w\/]+)\b/gi

You're now allowing alphanumeric and slash characters (hence the need for a "range" of characters, denoted by square brackets.)

Mitya
  • 33,629
  • 9
  • 60
  • 107
0

This one will do it: Try:(will match /Text)

/\/(\w+)\b/gi
Reto
  • 1,305
  • 1
  • 18
  • 32