JavaScript even matches lost using match on a regex

i'm trying to match a *xxx pattern such as "*test", "*love" "*anything" (like hashtag)

i basically tried:

"*aaa *eee *rrr *ttt".match(/(\s|^)(\*[a-z0-9]{3,150})(\s|$)/img)

returns only odd logical matches: "*aaa " and "*rrr "

When matching, i guess engine "marks" the whole matching digits as "used" and so are removed from testing to next block. and so, what can be the "nothing" digit, because starting "^" is not there, and there is nothing before second match.

Does anyone have an idea to fix it?

Answer:1

The problem is that the space is getting consumed by the previous match and thus unavailable for the current match.

You can use look-ahead - (?=\s|$) instead of (\s|$). Try:

(\s|^)(\*[a-z0-9]{3,150})(?=\s|$)

See this for more on look-ahead.

Test.

But in this case you can remove the check for the following space altogether, since [a-z0-9] can't match a space. Following from this, another option is changing it to: (if this fits your requirements)

(\s|^)(\*[^\s]{3,150})

[^\s] means not white-space.

Answer:2

Hi guys i am using node server for data fetch and and client side is my ionic framework for android application(phonegap). so in my computer browser i hit localhost:8080/sessions (or 10.129.86.47:...

Hi guys i am using node server for data fetch and and client side is my ionic framework for android application(phonegap). so in my computer browser i hit localhost:8080/sessions (or 10.129.86.47:...

  1. ionic cross domain issue
  2. ionic cross domain
  3. ionic cross domain request
  4. ionic http get cross domain

Right now, I have the user inputting a chemical formula, say Cu(NO3)2, and splitting the elements and numbers into an array. This code works for all formulas except for those with parentheses. (which ...

Right now, I have the user inputting a chemical formula, say Cu(NO3)2, and splitting the elements and numbers into an array. This code works for all formulas except for those with parentheses. (which ...

  1. regex split parentheses
  2. regex split parentheses java
  3. regular expression split parentheses

The following script pulls the data from my database and creates a pagination. The pagination works, but I would like to add a conditional statement which differentiates the level of the user. User ...

The following script pulls the data from my database and creates a pagination. The pagination works, but I would like to add a conditional statement which differentiates the level of the user. User ...

  1. pagination conditions cakephp
  2. laravel pagination conditions
  3. cakephp 3 paginate conditions

I'm trying to build a Rock Paper Scissors game in JavaScript, but also have it where the computer outputs images to the HTML document. I've tried everything I know, and it won't work. Here's the HTML: ...

I'm trying to build a Rock Paper Scissors game in JavaScript, but also have it where the computer outputs images to the HTML document. I've tried everything I know, and it won't work. Here's the HTML: ...

  1. make images change automatically html
  2. how to make images change in html
  3. how to make images change in javascript
  4. make a change images
  5. how to make images change in powerpoint
  6. how to make images change in css
  7. how to make images change on website
  8. make background change images
  9. make background change images css