News Articles regex

String.prototype.split with RegEx that keeps separator

I want to use String.prototype.split to split a string using a RegEx pattern as separator. However the matched separator itself should also be included into the result. The pattern can be described like this: Has to start and end with double brackets. In between those only lowercase letters and periods are allowed. However, a period […]

Check whether a string matches a custom regex in Javascript

let weekNumber = 2021-W32; if(customRegex.test(weekNumber)){ //true code; } else { //false code; } Hi All, Please suggest me custom regex to valid the week number of the year. The format should be 202X–WXX Where X is between 0-9, only 1 digit in 202X, 2 digit in WXX. Thanks for the help. Source: JavaSript – Stack […]

Is there a way to do a lazy lookbehind?

I have some HTML text like below. <div style="background:#e0dddd; color:#333399; font:9PT ‘arial’; padding:10px; margin-left:-30px; "> <div> <strong>Some text here1 </strong><br /> 2021-08-08 </div> <div><p> Some text here2</p> </div> <div class="download"> <a href="index.php?obj=notice_id=1734">View Detail …</a> </div> </div> <div style="background:#e2ecf4; color:#333399; font:9PT ‘arial’; padding:10px; margin-left:-30px; "> <div> <strong>Some text 3</strong><br /> 2021-08-06 </div> <div><p> Some BE text […]

Regex match from array of strings in JavaScript [duplicate]

I am facing a bit problem in Regex. I want to find the start and end index of the complete matched string in the input string. e.g. I have an array of strings like ["a", "aa"] and I have a text like I like a problem aa I am doing with iteration of array strings. […]

How to reference the first argument In the second argument of the replace method of javascript?

"abcd".replace(/a/, "b") but instead of the fixed value of "b", the second argument should be dependent on the first. For example: "abcd" -> "<div>a</div>bcd" "zbcd" -> "<div>z</div>bcd" Source: JavaSript – Stack Overflow

RegExp to match words separated by commas, allowing empty (no words)

I am trying to match these kind of inputs: hi hi,no hi,no,yes (…any amount of words separated by commas) (also empty, no words) Inputs that should be forbidden: hi, , hi, no (notice the space at the left of the last word) hi ,no (notice the space at the right of the first word) RegExp: […]

How to match anything between * but not match * * *

I’m using the following regex to match anything between *: /*([^*]*)*/g It should match this: *text* *text* *text text text* The match messes up if there are * * * in a line: *text* * * * *text* *text text text* https://regexr.com/63of6 What’s the simplest way to prevent * * * from messing up the […]

How to write a regExp in js with this particular condition

Anyone knows how i should wite a regular expression in js with condition to get all sybols except ">" and "<"? Source: JavaSript – Stack Overflow

how to write a regex to detect a string longer than 5 characters in javascript?

Basically, any string with a sequence of characters numbering more than 5 where none of the characters are whitespace characters should be detected. example: "123456" -> TRUE "123 56" -> FALSE Source: JavaSript – Stack Overflow

Regex matching incorrectly in JS, but correctly on regex101 (with ECMAScript mode)

I am trying to match a string and I’ve made a regex for it which I have tested on regex101, but for some reason when I run the regex on my website, I don’t get the same result. Here’s the regex in question: /(?<!//[^rn]*)([*+<=^]+|-(?!>)|(?<!-)>|(?<!/)/(?!/))+/igs And here’s the test string init() { self -> services = […]

How to match regex between 2 strings JavaScript

I keep getting this error when trying to use this Regex in JavaScript. SyntaxError: Invalid regular expression: unrecognized character after (? var matches = navigator.userAgent.match(/(?<=Version/)(.*?)(?= Safari)/); Source: JavaSript – Stack Overflow

Repost – JavaScrpt split line Regex – ‘double quote’ inside ‘double-quotes’

I’m so sorry if I missed details on the 1st post which is closed. I added comma within double quotes to the string, and I added the string into variable. I cannot simply split on comma, thanks. 🙂 ===Original Post=== Basically, I need to split a line into an array. But I encountered error when […]

How to use regex to split a string by comma or linebreak in javascript?

I have a React application where I need to split user input (string) by either comma or linebreak to later map them out as a list. Each one work individually, but when I have 2 different examples on the page only one of them work and the other one is read as one string. Input […]

Validate if a string is match to specific formats (margin css property) with regex

How do I confirm that a string matches the following formats: 1px 1px 1px 1px 1px 1px Where there is the number 1 we can have 1 or 2 digits (0-9). What is the regex that works for both cases? What is the regex for each case independently? Source: CSS – Stack Overflow

Excel Power Query regex return matches and submatches using web.page

Using Power Query in Excel I am attempting to parse a text column to extract allocations. The original text is from an application where the user can enter the allocations in a free text field, as a result there are many different formats. I am using regex to split the allocations and handle the variety […]

Replace character before date match

I want to replace the underscore that precedes a date in a string e.g. thequick_brown_20210813_fox To: thequick_brown_red_20210813_fox I.e. replace that underscore with _red_ This captures the date part: (20d{2})(d{2})(d{2}) And to replace I assume I can just use str.replace But not sure how I can capture the underscore that precedes it. Source: JavaSript – Stack […]

Regex Expression (?=.*) means [duplicate]

Can anybody please let me know what does (?=.*) in the below code means?? ^(?=.*[@*#])(?=.*[a-z])(?=.*[A-Z])[[email protected]*#]{8,}$ Source: JavaSript – Stack Overflow

Find all <img> tags and replace them by their src

I have a string of a mix of text and tags like so: This is a comment <img width="232" alt="CleanShot 2021-08-13 at 10 03 [email protected]" src="https://user-images.githubusercontent.com/10532381/129324867-83b2e2bf-52c7-4dc6-a8b6-760194e2a875.png"> Some more comment <img width="232" alt="CleanShot 2021-08-13 at 10 03 [email protected]" src="https://user-images.githubusercontent.com/10532381/129335514-e7e921e9-eb1e-4848-b197-a2438bcc7bd3.png"> This is the end of the comment I would like to create a function that replaces the […]

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.