Latest Questions tagged Regex

Browse all latest questions tagged Regex

Published 31 Aug, 2022
Python - Regex subsequence matching

I'm using python but code in any language will do as well for this question. Suppose I have 2 strings. sequence ='abcd' string = 'axyzbdclkd' In the above example sequence is a subsequence of str...

Published 20 Aug, 2022
Python - Why does flake8 give the warning F821 -- undefined name 'match' when using with Python 3

Please consider the following example, which finds the first String in a list that contains the Substring "OH": list = ["STEVE", "JOHN", "YOANN"] pattern = re.c...

Published 29 Aug, 2022
Python - Matching strings with re.match doesn't work

From this link I used the following code: my_other_string = 'the_boat_has_sunk' my_list = ['car', 'boat', 'truck'] my_list = re.compile(r'\b(?:%s)\b' % '|'.join(my_list)) if re.match(my_list, my_othe...

Published 04 Aug, 2022
Jquery - jQuery/JavaScript clean string so only words exist

I have this string with text mixed together with tabs, spaces, CR/LF and maybe more special characters as well. How can I go about cleaning the string so that I only have the words left. I tried the...

Published 29 Aug, 2022
Python - Python - Locating the position of a regex match in a string?

I'm currently using regular expressions to search through RSS feeds to find if certain words and phrases are mentioned, and would then like to extract the text on either side of the match as well. For...

Published 16 Apr, 2022
Javascript - Regex for entering letters without emojis

Is there any examples of regex for entering text(letters) without emojis ? I tried to inverse regular expression but it works not correctly /(?!:\ud83c[\udf00-\udfff]|\ud83d[\udc00-\ude4f]|\ud83d[\...

Published 21 Aug, 2022
Java - Java regex: check if word has non alphanumeric characters

This is my code to determine if a word contains any non-alphanumeric characters: String term = "Hello-World"; boolean found = false; Pattern p = Pattern.Compile("\\W*"); Matcher m = p.Matcher...

Published 01 May, 2022
Python - Do Python regular expressions have an equivalent to Ruby's atomic grouping?

Ruby's regular expressions have a feature called atomic grouping (?>regexp), described here, is there any equivalent in Python's re module?

Published 23 Apr, 2022
Javascript - How can I insert a character after every n characters in javascript from backwards?

A function that will insert 1st parameter after n(2nd argumanet)th times from backward const string = "abcdefg"; const backWardInsert = (str, num) => { // Do the stuffs // Here is what I"ve...

Published 24 Aug, 2022
Python - Regex not start with dot or end with dot

I need a regular expression that does not start with a dot or end with [-_.]. This regex works but fails for the first condition; it does not start with dot: ^[A-Za-z0-9][^.]*[^-_.][A-Za-z0-9]$ Fo...

Published 26 Apr, 2022
Python - Different behavior between re.finditer and re.findall

I am using the following code: CARRIS_REGEX=r'<th>(\d+)</th><th>([\s\w\.\-]+)</th><th>(\d+:\d+)</th><th>(\d+m)</th>' pattern = re.compile(CARRIS_REGEX,...

Published 16 Apr, 2022
Javascript - What's the best way to validate an email address in JavaScript?

What's the best way to validate an email address in JavaScript with a regular expression?

Published 24 Apr, 2022
Python - Python lambda with regex

When using re.sub() part of re for python, a function can be used for sub if I am not mistaken. To my knowledge it passes in the match to whatever function is passed for example: r = re.compile(r'([A...

Published 04 Aug, 2022
Jquery - How to write a multilingual regex validation for Russian + Persian + Chinese + English languages?

I have finally figured out how to validate inserted russian text in my tag by mask = jQuery.extend({unitprmask:/^\d+(\.\d{1,1})?$/,expressmask:/^\d+(\.\d{1,1})?$/,qtymask:/^\d+(\.\d{1,1})?$/,y...

Published 03 May, 2022
Python - In python, how to 'if finditer(...) has no matches'?

I would like to do something when finditer() does not find anything. import re pattern = "1" string = "abc" matched_iter = re.finditer(pattern, string) # <if matched_iter is empty (no matched fo...