Skip to content
Advertisement

Tag: regex

RegEx match exactly 4 digits

Ok, i have a regex pattern like this /^([SW])w+([0-9]{4})$/ This pattern should match a string like SW0001 with SW-Prefix and 4 digits. I thougth [0-9]{4} would do the job, but it also matches strings with 5 digits and so on. Any suggestions on how to get this to work to only match strings with SW and 4 digits? Answer Let’s

Regex for a valid hashtag

I need regular expression for validating a hashtag. Each hashtag should starts with hashtag(“#”). Valid inputs: 1. #hashtag_abc 2. #simpleHashtag 3. #hashtag123 Invalid inputs: 1. #hashtag# 2. #hashtag@hashtag I have been trying with this regex /#[a-zA-z0-9]/ but it is accepting invalid inputs also. Any suggestions for how to do it? Answer To answer the current question… There are 2 issues:

Regex to allow only numbers and decimals not working in Javascript

I am trying this below code and the regex isn’t working and it is allowing all the characters in the input box. Desired: Input text box should not accept any other character other than numbers and decimal point. Answer Here’s an alternative way. I’m using the oninput event that is triggered on every value change by user (not only key

Match and replace a substring while ignoring special characters

I am currently looking for a way to turn matching text into a bold html line. I have it partially working except for special characters giving me problems because I desire to maintain the original string, but not compare the original string. Example: Given the original string: And wanting to match: To get the desired result: The way I’m currently

Determine if a path is subdirectory of another in Node.js

I am working on a MQTT handler for which I want to emit an event for each parent directory where there is a event listener. For example: If there are the following MQTT paths available, where there are subscriptors –there are event listeners for these paths– test replyer/request test/replyer/request And someone publishes on topic test/replyer/request/@issuer, there should be 2 events

How do I convert a string to spinal case in JavasScript?

I am stuck on this coding challenge Spinal Tap Case from freeCodeCamp. Essentially I don’t know how to get the last check to execute. This is the last check: spinalCase(“AllThe-small Things”) should return “all-the-small-things” And this is my code: I do realize the last else ifcondition should go first however I didn’t get the syntax right. Thanks in advance! Answer

Matching words starting and ending with same vowel letter

I am trying to come up with a regex to match words starting and ending with same vowel. My question is, is this an elegant all-encompassing solution or am i missing something? So far this is what I have come up after a quick brainstroming. My preferred environment is javascript/python without special libraries etc. Thanks for helpful suggestions. soln. 1)

Advertisement