Javascript – Grouping text with regex
consider I have a text like : Some text 1 `special text` Some text 2 I can get "special text" with regex, but I want other parts of the text too as an array, something like this : [ Some…
consider I have a text like : Some text 1 `special text` Some text 2 I can get "special text" with regex, but I want other parts of the text too as an array, something like this : [ Some…
Instructions: The sumNums function takes a string as an argument. It should return the sum of all the numbers contained within the string. If there are no numbers in the string, sumNums should return 0. Consecutive digits should be taken…
I'm trying to create a regex that matches numbers greater than or equal to 150 000, considering spaces as thousand separators. Here is the regex I tried: ^(150s*000|1[5-9]d{2}(s*d{3})*|[2-9]d{2}(s*d{3})*|d{1,2}(s*d{3})+)$ And here is the JavaScript code I used to test it: const…
I need to check if a given string is valid. For me, the following and any other similar combinations are all valid URLs 'https://example.com/api/', 'https://www.example.com/test-subpath', 'https://www.example.com', 'example.com/test/page', 'www.example.com', 'www.subdomain.example.com', 'https://www.subdomain.example.com', 'subdomain.example.com', 'http://subdomain.example.com', 'https://subdomain.example.com' while 'user-service/api/' is invalid. I tried parse_url()…
We need to write a RegEx which can validate a CAGE Code A CAGE Code is a five (5) position code. The format of the code is the first and fifth position must be numeric. The second, third and fourth…
I've created a regex pattern to match sequences of digits that can be ascending or descending, like 12345, 123, 321, 6789, 7654, etc. However, I believe this approach may not be the most efficient or professional way to achieve this…
I have some text: const str = `This <a href="https://regex101.com/" data-link-id="431ebea7-1426-65a5-8383-55a27313dc51">is a test link</a> which has a hyperlink, and <a href="https://regex102.com/" data-link-id="d62dc3eb-7b3d-953e-4d7a-987448e6928d">this is also</a> a hyperlink.` I'm trying to match all a tags, but my regular expression just returns the…
I want to create a simple text templating that allow defining placeholders using {0}, similar to what .Net does using string.format method. Basically I want this: format("{0}", 42), // output `42` format("{0} {1}", 42, "bar"), // output `42 bar` format("{1}…
I am trying to download files with the chrome.downloads.download(...). The filename is given externally, so I don't know the characters inside. If it contains invalid characters, the function download will throw an error Error: Invalid filename. Is there a regex…
I want to copy past a huge list of properties rather than type them all out again. However I want to avoid copy their assignments. The solution I'm trying involves a cmdF regex in VSCode. Then selecting all found matches.…