Skip to content
Advertisement

Tag: regex

How do I combine these three regex into one?

I’m trying to make a regular expression that only accepts: Min 100 and atleast 1000 characters, characters “,’,<,> aren’t allowed, two full stops one after another aren’t allowed. This is what I have for now: ^.{100,1000}$ → for 100 to 1000 characters ^[^”‘<>]*$ → for the characters that aren’t allowed ^([^._]|[.](?=[^.]|$)|_(?=[^_]|$))*$ → doesn’t allow 2 consecutive dots How do I

Certain number question being missed in regex

I have the following if statement that removes the first instances of a number followed by the period. However, I am noticing it is missing to catch some of them (ex. “16.”, “23.”, “24.”, etc.) and not sure why. Here is the function: The following for loop extracts the question from the google form: The following example is the type

Regex: Check if character exists in string and adjust rules accordingly

I am writing a regex to try and filter out invalid urls. This should be simple enough – a million examples are available online, I ended up using this one: ((https?|ftp|file)://)[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]. However, our specific requirements state that the url must end in either “?” or “&”. This should also be fairly simple, it can be done by adding (\?|\&) to

Regexpr with a string

I have to get the result from this regular expression; the regular expression is a string in a variable: but the xlslHrefRegExpResult variable is null. If I use: without the string variable containing the expression, the result is achieved. Where is the error using a string to build the regexp? Answer The correct code should be: You had too many

Whats wrong with this regex to remove substring?

Trying to strip out the extra addressee from an address string. In the example below, dba bobs is the targeted string to remove. The above yields: When the desired is: What am I doing wrong? Sometimes the input has a ‘n’ before the ‘dba’. Answer You can simplify your regex to: /b(attn|co|dba|fka|dept)b.*/gm Test here: https://regex101.com/r/TOH9VV/2 EDIT: Included suggestion of user

Regex limit the number of letters total in the entire string

I have this expression which is almost what I need: except, I need to only allow 4 letters total (4 in the beginning and 0 in the end,3 and 1, 2 and 2, 0 and 4, etc…) allowed inputs: 11abcd11 1abcdefg123 abcd1234 unallowed inputs: 1abcd11 abcd123 1abcd12 is there a way to achieve this? thanks! Answer To make sure there

node – How to replace part of an url

I have an array of urls like this: I need to search inside it to match the user input with the subdomain part of the url, I’m trying with thism line of code to achive it: If the input is find, I need to replace the second part of the url, in my case /foo-bar with /foo-baz or /foo-baz-bar to

Advertisement