Skip to content

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 digit…

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 als…

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…

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 someo…

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 librarie…