OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

JavaScript Split String with regex - match (how to replace match regex into split function)

  • Thread starter Thread starter PRATAP
  • Start date Start date
P

PRATAP

Guest
Code:
let s = "AbcDefGH"
s.match(/[A-Z]+[a-z]*/g)
["Abc", "Def", "GH"] // This is what expecting with split function

Code:
s.split(/(?=[A-Z]+[a-z]*)/g)
["Abc", "Def", "G", "H"] // "G" and "H" are separated.

My Question is how can I replace match regex into split function to get the same result of match.

Please explain what for ?= when match regex is translated to split function

Thanks

<pre><code>let s = "AbcDefGH"
s.match(/[A-Z]+[a-z]*/g)
["Abc", "Def", "GH"] // This is what expecting with split function
</code></pre>
<pre><code>s.split(/(?=[A-Z]+[a-z]*)/g)
["Abc", "Def", "G", "H"] // "G" and "H" are separated.
</code></pre>
<p>My Question is how can I replace match regex into split function to get the same result of match.</p>
<p>Please explain what for <code>?=</code> when match regex is translated to split function</p>
<p>Thanks</p>
 

Latest posts

Top