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
Tag: regex
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
Find words from array in string, whole words only (with hebrew characters)
I have to build a RegExp obejct, that will search words from an array, and will find only whole words match. e.g. I have a words array (‘יל’,’ילד’), and I want the RegExp to find ‘a’ or ‘יל’ or ‘ילד’, but not ‘ילדד’. This is my code: What I have tried: I tried this code: It works well, but it
Regular expression to accept decimal numbers between 0 to 100
My requirement is a regular expression it accepts decimal values between 0 to 100 (like 1,2,3,….,99, 0.1,0.2,0.3,…..,99.9, 0.01,0.02,0.03,…..,99.99, 00.01 to 99.99). I found one solution but it accepts only decimal values like 00.01 to 99.99. Answer How about: Explanation:
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
Regex Pattern for checking the first letter of each word in a string if its Uppercase in Javascript
for example my string is Foo Bar. this string should match the pattern. if the string is Foo bar. the string should not match. if the string is Foo Bar Foobar the string should match if the string is Foo. it should also match. so far I only have this pattern Basically I will only accept a string where each
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)