Skip to content
Advertisement

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-F0-9^!G-Z]/i but for some reason, it returns strings that have

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 lowercase text to create hierarchy

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’m trying to search a specific string like 9.7 in an array using

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 whereas is a simple function decreasing the counter and returning an ‘X’ or

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? Answer For the

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 can try something

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 “assistant-attorney” and also get true. Can’t figure out if I should use word boundaries, or check if string does not

Is it possible to use only lookaround to match characters that are not repeated immediately before and after?

For example, to match the first slash after the domain name in the URL. Intent: Only match ‘/’ in ‘.com/…’ but not any ‘/’ in ‘https://’. The above [A] returns the correct match, but [B] is the kind of expression I want (although it did not match any characters), that is, to use the / character only 1 time in

Advertisement