Skip to content

Tag: regex

Need help figuring out how to write this Regex properly

I am trying to make a regex test that returns true for the following conditions: Can only have letters A-F (case insensitive) First character must be ‘#’ Can have numbers 0-9 Does not have punctuation The order does not matter except that string[0] should be ‘#’. So far I have: /^#[A-F…

Regex for hashtags tree takes too long to execute

In our app we have topics which user can create, and each topic must have it’s own hashtag (or hashtags hierarchy). We have this kinda Regex for validation: What i need is for user to be able to create hashtags which have structure like this: (#) symbol Text in lowercase Optional slash (/) followed by l…

Regex test method returning more than a specific string [closed]

Closed. This question needs debugging details. It is not currently accepting answers. Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question. Closed 11 months ago. Improve this question I&#…

how to replace some character with certain repeting regex

this is the log the output must be====>|~~X~~~X2~2~~22~2~~~~2~~~| here the code i’ve try: how to make /2/g just replace certain repeating i wanna make code above same function with this function duckShoot(ammo, aim, ducks) { } Answer or you can keep the ‘old’ replace with the regex wherea…

Regex match any js number

So as an exercise I wanted to match any JS number. This is the one I could come up with: This however doesn’t match the new syntax with underscore separators (1_2.3_4). I tried a couple of things but I couldn’t come up with something that would work. How could I express all JS numbers in one regex…

How to add the option to allow only one space in a regex

I want a regex that will allow only one space within a set of characters. I have the below regex which doesn’t accept space. The below regex only supports strings like 1. @alia 2. @ranbir 3. @shilpa I want a regex that will allow strings like 1. @alia bhat 2. @ranbir kapoor 3. @shilpa shetty Answer You …

How to regex match words with/without hyphen

I’m having a lot of difficulties matching strings in JavaScript using regex. Problem is when I match strings like “assistant-attorney” with “attorney” it returns true. I cannot ignore/forbid hyphens, as I also want to be able to match “assistant-attorney” with “…