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
Tag: regex
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
Converting a RegExp constructor to be Safari-compatible
I have this regexp constructed pattern I’m passing a string variable to. This works perfectly in Chrome, but won’t work in Safari. Is there a way I might be able to convert this code to be compatible across browsers? Thank you! Answer You can use The (?!Bw) negative lookahead requires a word boundary position if the next char is a
Regular Expression Allowing Input For Only Numbers and One Decimal
I want an input text box that restricts users to only enter numbers and one decimal point. The regular expression I am using currently is /[^d.]/g. Currently this allows the user to only input numbers and decimals but also allows for more than one decimal number. I am using it for a text box to allow only a string of
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
How to capture all but last token in regex when last token can be optional
I have a string in the following format: aaa!bbb.200 where aaa can be anything (any length) bbb can be anything (any length) except ! ! & .200 are optional (can be any 3 digit number) i want to capture bbb and 200 for example: aaaaa!bbbb.200 i want to capture bbbb & 200 aaa.400 i want to capture 400 aaa!bb i
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