Extract digits from a string within a word

I want a regular expression, which returns only digits, which are within a word, but I can only find expressions, which returns all digits in a string. I’ve used this example: text = ‘I need this number inside my wor5d, but also this word3 and this 4word, but not this 1 and not this 555.’… Read More Extract digits from a string within a word

How do I get the characters inside a pair of parentheses which are immediately followed by a specific string?

My string looks like this: (left.e0_coefficient*right.Scalar) e₀ + (left.e1_coefficient*right.Scalar) e₁ + (left.e2_coefficient*right.Scalar) e₂ + (left.e3_coefficient*right.Scalar) e₃ I want to get the expression thats contained in the parentheses preceeding e₂ => left.e2_coefficient*right.Scalar I tried using \((.+?)\) e₂ however despite it being lazy (non-greedy) the capturing group still contains everything from the first parenthesis in the string… Read More How do I get the characters inside a pair of parentheses which are immediately followed by a specific string?

Javascript regex to validate a decimal before inserting into MySQL

I have a regex to validate a decimal value before inserting into MySql database, but there is an issue with it. It is allowing a just the negative symbol with no digits after it. So for example, I’m validating against a decimal(7,2). Here is my regex: ^[+-]?\d{0,5}(?:\.\d{0,2})?$ And here are the valid/invalid values Valid -1… Read More Javascript regex to validate a decimal before inserting into MySQL

Javascript match anything until pattern

Given example-123, I need to extract just example. Also example could be: example-example-345, in which case I need example-example. This is the pattern I’m looking for: > str.match(‘-[0-9]{1,}$’)[0] ‘-123’ I tried: str.match(/(.*)-[0-9]{1,}$/) ‘example-123’ and str.match(/(?s).*)-[0-9]{1,}$/)[0] Uncaught SyntaxError: Invalid regular expression: /(?s).*)-[0-9]{1,}$/: Invalid group and str.match(‘[^-[0-9]{1,}$]’) null and str.match(‘(.*)[^-[0-9]{1,}$]’) null and str.match(‘/.*/[^-[0-9]{1,}$]’) null and str.match(‘.*^(-[0-9]{1,}$)’) null… Read More Javascript match anything until pattern

regEx function not does not pass test

Just wondering what could be wrong with my regEx function, is returning false, is there a better or cleaner approach to mimic startsWith as my application has an embedded JS engine that is ecma 1.8.5 spidermonkey function startsWith(i,s) { var regEx = new RegExp(“/^”+i+”/”); console.log(regEx) return regEx.test(s); } const myString = “hello world”; console.log(startsWith(“hello”,myString)); update… Read More regEx function not does not pass test