Tony
Tony

Reputation: 12695

Regex for the string with '#'

I wondering how should be the regex string for the string containig '#'

e.g.

abc#def#ghj#ijk

I wanna get

I tried #[\S]+ but it selects the whole #def#ghj#ijk Any ideas ?

Edit

The code below selects only #Me instead of #MessageBox. Why ?

var m = new RegExp('#[^\s#]+').exec('http://localhost/Lorem/10#MessageBox');

if (m != null) {
   var s = '';

   for (i = 0; i < m.length; i++) {
     s = s + m[i] + "\n";
   }
}

Edit 2

the double backslash solved that problem. '#[^\\s#]+'

Upvotes: 0

Views: 123

Answers (2)

MvG
MvG

Reputation: 60868

Try #[^\s#]+ to match # followed by a sequence of one or mor characters which are neither # nor whitespace.

Upvotes: 3

Felix Kling
Felix Kling

Reputation: 816462

Match all characters that are not #:

#[^#]+

Upvotes: 2

Related Questions