Match string with regex to get substrings between '='?

Sample string =aa=bb=cc=dd= .

I tried

 string.match(/=(\w*)=/) 

but returns only aa .

How to find aa , bb , cc and dd from example string?

+4
source share
5 answers

This regular expression will clearly meet your requirements and place the non, delimiter part in the first capture group:

 =([^=]+)(?==) 

Unfortunately, JavaScript regex has no appearance, otherwise it can be done much easier.

Here is the code:

 var str = '=([^=]+)(?==)'; var re = /=([^=]+)(?==)/g, ary = [], match; while (match = re.exec(str)) { ary.push(match[1]); } console.log(ary); 
+4
source

var values = yourString.split('='); You will get an array with all the necessary values.

+2
source

I believe that /[^=]+/g should suit your needs: try it !

+2
source

Description

this regular expression will write all unequal characters in your string

=([^=]*)(?==)

enter image description here

Example

Real-time example: http://www.rubular.com/r/vPW2GJqBWP

Sample text

 =aa=bb=cc=dd= 

Matches

Capture Group 1 will have the following

 [0] => aa [1] => bb [2] => cc [3] => dd 
+1
source

Just use just:

 string.split('=') 
+1
source

Source: https://habr.com/ru/post/1490306/


All Articles