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

  • #def
  • #ghj
  • #ijk

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#]+'

Answers


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


Match all characters that are not #:

#[^#]+

Need Your Help

Set JMenu Margin not working

java swing jmenu jmenubar preferredsize

I'm creating a JMenuBar with some JMenu and set margin in each JMenu. But the given margin not working in each JMenu. How to setMargin of JMenu correctly?

Using @Version in spring-data project

java hibernate spring-data spring-data-jpa spring-data-rest

I've been working on a RESTful webservice with spring-data. A few days ago a special spring-data jpa REST framework was released.