News Articles regex

What is the RegEx that replace "`" with opening and closing html tag to use in JS `.replace` [closed]

What is the RegEx that will convert the "`" to opening and closing html tags. Example: This `is` a string with some `words` in it. Will become: This <pre>is</pre> a string with <pre>words</pre> in it. Source: JavaSript – Stack Overflow

Javascript Regex pattern for 9 alphanumeric characters, dash & space allowed [closed]

Javascript Regex pattern for 9 alphanumeric characters, dash & space allowed Source: JavaSript – Stack Overflow

Regex to replace dots with new line but not for number

I have the following regex will replace dot with a new line But what if I want to skip numbers var mystring = ‘’; mystring = mystring.replace(/./g,’n’) But what if there are numbers, I want to skip var mystring = ‘’; I want to keep the number 123.23 without going to a new line Please […]

RegEx works in online testers, but returns `null` match both in my app and the online sandboxes

I am working on a regular expression that would extract all headings from a parsed MDX string. It looks fine in two online testers (,, but it doesn’t work (returns null match) in my app. It doesn’t work on and Stack overflow snippets either (as you can test below). The regex is: /(?<=mdx()"hd(?:(?!),).)*/gi […]

Regex – positive, max 5 digits before decimal, max 2 decimal places separated with comma or dot

I’ve got a problem with creating regex. I need to allow only positive number with maximum 5 digits before decimal part, max 2 decimals places separated with comma or dot. Right now i have this: /^[+]?d{1,5}([.,]d{0,2})?$/ but it limits all signs to 5. So I need to allow: 99999.99 9999.99 99999 9.9 But block: 999999 […]

How can i bold the word before colon only if colon exists in line by regular expression

These four lines are store as an array of objects in ptr ["NF: (Chuckling)","EM: And we taught not very long. Ms. Fox (ph) took my place. I met Ethan and we","were married in February (Chuckling). I had taught from September to February–","NF: Wow!"] I am trying to show these in jsx line by line and […]

Regex expression for various conidtions

I hope everyone is doing great! I need your help. I am not so much perfect with regex. What I want to do is Input = /smithwicks-ale-270439#.YS_D8NNKj0o Output = 270439 Input = /270439#.YS_D8NNKj0o Output = 270439 Please tell me how can I achieve it. Source: JavaSript – Stack Overflow

Remove part of string using regex and replace

give a string like this (it can be any pattern, but the following format): lastname/firstname/_/country/postalCode/_/regionId/city/addressFirst/addressSecond/_/phone I am making a function that, when I pass some address parts, the function will return those parts and remove extras part that are not requested and mantaining maximum one spacing _ if many where removed: FE : exs : […]

Javascipt – How to add multiple conditions in regex in one line? [duplicate]

I am new on regex. Why is my regex not working? /A/gi, "z" && /B/gi, "x" && /C/gi, "y" && /D/gi, "a" let convertedVal = TextValue1.replace(/A/gi, "z" && /B/gi, "x" && /C/gi, "y" && /D/gi, "a"); I want to convert "A" to "z" and "B" to "x" and "C" to "y" and "D" to a […]

Callback from Peggy generated parser

I want to parse a string that is generated inside a class instance by calling a peggy generated parser. One of the parsing actions needs to invoke a function defined inside the class instance, so that I have access to the environment of that instance, including this. How can I make that happen? Source: JavaSript […]

How to match all tags containing specific word with regex?

I’m trying to find all <divs> in an html containing the same word, it could be either in the class="" or in the id="" Example: <div id="chat_widget_th" class="bg-warning checkbox chat_open_ts">…</div> <div class="bloom chat_inside_th dark_yellow>…</div> <div id="opened_widget_chat" class="active show">…</div> <div class="chat_child modal show fade">…</div> These four <divs> are from different pages. They all correspond to a […]

prevent app from creating windows system folders using regex?

I’m building a browser-based app which allows users to create folders with some .json files (not big deal). The thing is, the framework that I’m using (NW.js) doesn’t appears to care about allowing users to create folders named "CON" or "NUL"; These are not supposed to be created, the files inside just vanish and it’s […]

SMS client side validation – two different character limits on cyrillic and latin

I have a SMS text field where by requirement I need to limit my character limit depending on the type of language: 160 limit for Latin language 80 for Cyrillic I have read about character classes and I found this topic interesting. regular expressions with the Cyrillic alphabet? I could use @"p{IsCyrillic}+" for Cyrillic and […]

Regex valid IP address [duplicate]

Can anyone pls confirm is this a valid IP address validator, does it verify all the IP addresses. If not pls suggest a regex (am using JS), which validates all IP addresses /^((([a-fA-F0-9][a-fA-F0-9]+[-]){5}|([a-fA-F0-9][a-fA-F0-9]+[:]){5})([a-fA-F0-9][a-fA-F0-9])$)|^([+-]?(?=.d|d)(?:d+)?(?:.?d*))(?:[eE]([+-]?d+))?([a-zA-Z](([+-]?(?=.d|d)(?:d+)?(?:.?d*))(?:[eE]([+-]?d+))?[a-zA-Z])+)$|(^([a-fA-F0-9][a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]+[.]){2}([a-fA-F0-9][a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]))$|(^([0-9]){15}$)/ Am new to regex Thanks in advance Source: JavaSript – Stack Overflow

How to I rearrange AND delete text in regex?

I’m trying to convert BB Code into markdown. The problem is, I can’t figure out how to delete and rearrange text. I have this: [url=]Example[/url] I want to take everything in between [url= and ] and everything in between ] and [/url] and rearrange it as [Example]( But when I try, it results in this: […]

remove everything within [] /[[^][]*]/g

Im trying to remove everything that is inside this: [] To example [abcd]word[efg] should be word. I tried to replace it like this but its not working for some reason. Does anyone know how to fix that? string = ‘[abcd]word[efg]’; string = string.replace(/[[^][]*]/g,””); console.log(string); Source: JavaSript – Stack Overflow

combine regex to match subgroups in different order

I have a string with may have one of the 2 below structure (w+){1}([!][a-zA-Z0-9>,]+)*([#]d+)? (w+){1}([#]d+)?([!][a-zA-Z0-9>,]+)* some examples would be "Abc1!deF2>Ghi3,4jlmNO!pQr5st#1400" "Abc1#1400!deF2>Ghi3,4jlmNO!pQr5st" The goal is to match as below ["Abc1", "!deF2>Ghi3,4jlmNO", "!pQr5st", "#1400"] ["Abc1", "#1400", "!deF2>Ghi3,4jlmNO", "!pQr5st"] I can manage to get the result with 3 regex, but not with 1 const a = str.match(/w+/) const […]

Javascript String template parsing for keywords

I have a string template with few dynamic keywords like: I am {{name}} from {{city}} For a given input string I want to match it against the template and extract the name and city from the input in Javascript. Eg. input I am Alex from Paris should give me name as Alex and city as […]

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.