Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Group first folder and the following files in Regex

I am trying to use regex to group the root folder of a package and to group the rest of the files in it.

I tried the following @package\/(.*)\/(\/*.+)$ with the test string @package/util/src/index.js:
Regex

But instead of grouping util/src and index.js I want to group for util and src/index.js. I thought the / between the groups in my regex would match on the first /. What do I miss?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You might write the pattern like this to not cross the first / and then capture the rest of the line using (.+)$ without optional repeating \/*

@package\/([^\/]+)\/(.+)$

Regex demo

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading