Questions tagged [regex]

Regular expressions provide a declarative language to match patterns within strings. They are commonly used for string validation, parsing, and transformation. Since regular expressions are not fully standardized, all questions with this tag should also include a tag specifying the applicable programming language or tool. NOTE: Asking for HTML, JSON, etc. regexes tends to be met with negative reactions. If there is a parser for it, use that instead.

Filter by
Sorted by
Tagged with
0
votes
2answers
14 views

How do I make an regular expression that findall text that is in between a and (b or c) in python?

I want to make a regular expression where it returns all the occurrence of text that is in between a and first occurence of b or c. so I tried this code: text = 'dfgahfjbjicij' re.findall('a(.*?)(b|...
0
votes
1answer
7 views

How can I get rid of part of a filename from a HTML IMG string in TextMate?

I'm using TextMate's RegEx find and replace. I have: <img src="filename-WxH.ext" alt="Bla"> And I want to make it: <img src="filename.ext" alt="Bla"> The only defined data I have is "-...
0
votes
2answers
31 views

I need to modify a string of text in a loop so that the program should copy paste same string but with a number incremented

I need this link to be modified and copy pasted again with number increased like examples shown below www.example.org/images?ID=7497&page=1&CategoryID=1&pagetype=null www.example.org/...
1
vote
1answer
21 views

How to extract a HTML tag pattern multiple times from a string?

I've got this pattern based on which I want to search a string to find all matches. After using findall(), only the last one matched is printed. The string which I want to process is below: '<...
1
vote
0answers
14 views

How to fix 'Invalid regular expression' using rails google analytics api?

I'm trying to use a regular expression in a pagePath filter but I always get a 'bad request' response, even though it's a well-formed regex (I tested it separately) my_regex = /\/\w{2}\/someword(\/?|\...
2
votes
3answers
30 views

Use lookahead for AND inside group together with OR '|' to Boolean list of matches

How can I get a Boolean list that indicates matches found of every group where a positive lookahead is used for 'AND' inside of one of the groups? I only want one Boolean returned for each group. ...
0
votes
3answers
45 views

Replace part of string with variable with Regex(Regular expression) condition match javascript

I was thinking is possible to replace this condition match to a link in the map method. The end goal, I want to replace address apt #number to be a link after it render. But the address is wrap with ...
0
votes
3answers
45 views

Regex capturing groups within logical OR

I have a set of strings I need to parse and extract values from. They look like: /apple/1212d3fe /cat/23e24a2f4 /auto/df5478eefd /somethingelse/1234fded It should match only apple, ...
1
vote
1answer
32 views

Regex to find date string

I have many sites on which I need to find the date, all of these sites have different templates, so I need a regular expression, here are examples of how dates are displayed on these sites: Saturday, ...
1
vote
1answer
21 views

parsing '\L' - Unrecognized escape sequence

To be honest, I can't understand why I'm getting this error. The test below fails with the folllowing message: Failed: System.ArgumentException : parsing '\L' - Unrecognized escape sequence \L. ...
-1
votes
2answers
45 views

How to extract data from a raw file with Python

Current code: import re file = open("d.txt", "rb") regex = r'((?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.(?:'\ '25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.(?:'\ '25[0-5]|2[0-4][0-9]|[...
1
vote
4answers
37 views

Java String Replace on an XML pattern

I have the following XML String: String XML = "<TEST><MESSAGEID>5435646578</MESSAGEID></TEST>"; The number in the xml string keeps changing so I want to do a string replace ...
1
vote
2answers
44 views

How to find substrings flanked by a specific character and replace with text of the same length in R?

In R, what is the best way of finding dots flanked by asterisks and replace them with asterisks? input: "AG**...**GG*.*" desired output: "AG*******GG***" I tried the following function, but it is ...
1
vote
2answers
58 views

Regex returning partial result

Regex is returning only partial result I have below regex which is returning only partial result Basically i am trying to find 2 consecutive words followed by a word which contains at least 1 upper ...
0
votes
2answers
26 views

combine regex patterns javascript

I have two regex patterns 1) re1 = /^[0-9\b]+$/ is for allowing only numbers in the input field 2) re2 = /^(7|75|750)$/ is for allowing first 3 numbers of input field to be "750". Now, I want to ...
-1
votes
0answers
9 views

Is there any way I can use the part of extracted value from regex and then filter the data and pass it to next thread in jmeter

I have a scenario in which I need to extract the maximum dynamic value from the response and pass it to the next thread. I want to extract 392 which is the highest number but I am not able to get ...
1
vote
3answers
33 views

Extract all substrings meeting criteria using R regex

I have an extremely long string in R and would like to extract all substrings that match a certain criteria. The string may look something like this: "some text some text some text [ID: 1234] some ...
2
votes
1answer
45 views

How do i modify this valid regex for use in c#? [duplicate]

I'm using https://regexr.com/ and https://regex101.com/ to create a regex that will be used to filter a list of files in a directory in a c# console application. The format Im am trying to match is ...
-2
votes
2answers
38 views

Python regex - How to find only chars around a '>' char, ignoring everything after or before a space [on hold]

I'm having a hard time with regex (still learning, but always difficult nonetheless). What I need to do is: Isolate everything around the char '>' from the rest by a space. Around it there might be ...
0
votes
1answer
29 views

Splitting up a deck list using a Regular Expression

I'm reading a deck list from a file and want to break this up into 3 sections. The quantity, the card name and the set. The set code is in the brackets. Here is an example of the data I have: 1 Dead ...
1
vote
2answers
26 views

Apify: PseudoUrl regex to match urls containing a given keyword

Apify PseudoUrl supports JavaScript-style regular expression to match against the URL. I tried following RegEx to match all the urls that contains a particular keyword - //not working http://www....
0
votes
0answers
14 views

Rewrite a url to pretty URL

I need to rewrite url to the pretty url with query string. Pretty url will be: https://dev.agency.com/private This needs to be rewritten to: https://dev.agency.com/player/5d4d1ecb9d41f/?//...
1
vote
1answer
31 views

Extract words from a string and split [duplicate]

I have a question. I have a very long string that also contain special characters. I want to use regex to extract the words and use the split function to get the desired output. ["one", "two", "...
-2
votes
1answer
34 views

IndexError when trying to convert a txt file into JSON format [on hold]

I am trying to use regular expressions to convert a .txt file into json. This is the text file's format: (a bunch of lines in each line there's a word and it's meaning seperated by , hello, Hallo ...
2
votes
5answers
53 views

I need to extract the first 6 digits and the last 4 digits of numbers in a string and delete leading zeros of the same with a regular expression

I need to delete leading zeros and extract the first 6 digits and the last 4 digits of numbers in a string with regular expression. I currently have a code that performs the operation I want, but I ...
0
votes
0answers
18 views

Adding a dynamic +1 to phone number as user enters it on form

I work for a company that gathers leads from the internet. Potential customers send us inquiries that include their phone number. We're having a problem because some folks are including a +1 at ...
0
votes
1answer
41 views

Regex - Match all numbers after a character [on hold]

I'm trying to find an R command that matches all numbers after the last instance of a certain character. For instance, let's say I have the following string - "123_123_abc_123-AB-DC-D4G6" How would ...
0
votes
1answer
38 views

is it possible to create a regex to remove entire domain (without subdomain) with Kotlin/Java including (or not) ports?

I look in many posts for a possible answer but none of them seem to solve my problem How to remove some part of URL by regex? Best way to Remove the domain from url Best way to Remove the domain ...
0
votes
0answers
24 views

Select string between two characters php [duplicate]

I have the following string D:\Folder\SubFolder\SubFolder1\SubFolder2\SubFolder3\SubFolder4\SubFolder5\199kjc2v0gwv6.jpg. What I want is to extract the following part 199kjc2v0gwv6, meaning between ...
-2
votes
0answers
24 views

Match digits at end of string, or match folders in string [duplicate]

Well hello there I need a regex that finds the last digits of a String, where the digits represents the amount of e-mail in a folder: "\\[email protected]\Inbox\TMP1337\XML 156" = "156" "\\[email protected]
2
votes
2answers
68 views

Regex to get string between nearest match [duplicate]

I have a scenario to get string between two words but the start words repeats multiple times in the text file and the end word is unique. I want the entire string between the last start word and the ...
-2
votes
1answer
37 views

Regex - Match elements of an array to different groups

I have a string which contains an array (array converted to a string). For eg: "['a', 'b', 'c', 'd']" (It's length is not fixed). I want to extract every element into different group. Something ...
0
votes
0answers
20 views

Regex for Alpha numeric and excluding begining space [duplicate]

Can you please help on regex to avoid special character and the space at the beginning of a sentence and it should allow the SPACE between words. I have tried with the Regex "(^[a-zA-Z0-9 ]*$)" but ...
1
vote
2answers
20 views

Extract Numbers from String - Custom

I'd like to extract "Most" numbers from a string and Add "JW" at the end. My values look like: RFID_DP_IDS339020JW3_IDMsg - Result = 339020JW RFID_DP_IDSA72130JW_IDMsg --> 72130JW ...
1
vote
1answer
38 views

Matching regular expression or leaving empty string when not found

this is my first post on this site so tell me if I mess something up. I need to find config files for files of the same name, with the difference being config files have 'str' at the end of them. some ...
0
votes
1answer
40 views

Parse HTML (with text) and img codes with regex

I'm working with php and regex. I want to parse HTML codes with text and img tags, and append to array. My code is not regular. I need this array output: ([0]=>( ["img"]=>'<img src="http://...
-1
votes
1answer
22 views

How can I grep a a string with quotes and a regex?

I have a JSON file that contains a list of files and their sizes. I'm trying to grep only the line containing the file size, which looks like this: "filesize": 10000000 I tried single quotes grep -...
0
votes
0answers
45 views

How to use group in regex?

I'm trying to use regex group into a Java regex. Regex boolean res = (frequency.matches("\\[((DAY (3[01]|[12][0-9]|[1-9]))|(EVERY DAY)|(EVERY (MONDAY|TUESDAY|WEDNESDAY|THURSDAY|FRIDAY|SATURDAY|...
-1
votes
0answers
18 views

JS - Run regex multiple times returning different results [duplicate]

I am really confused! I create a regex for an ipValidation. Like that: const ipRegex = new RegExp(`^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|...
0
votes
2answers
43 views

.NET RegEx: Find function and validate

In the project I'm currently working on signals from various sources are captured in triggered events. To analize the signals we want to use some querying and came up with a naming convention for our ...
-2
votes
0answers
23 views

preg_match(): Unknown modifier '|' [duplicate]

I use the pattern in laravel validation regex but it gives me this error. preg_match(): Unknown modifier '|' The pattern is: [^><#@*|(\u00C0-\u00FF)]|[a-zA-Z1-9_-]|[!$%^&] I want to ...
0
votes
0answers
20 views

How to cut a character from my regex match [duplicate]

I want to get a number from a string for a Graylog grok extractor. Graylog uses the Java Pattern class. I'm looking for the last number. 08/23/20/19 09:05:27 Total number of objects backed up: ...
0
votes
4answers
59 views

Getting all of the ungrouped parts of a string

I want to separate a string into two variables and the way to indicate this in the regex pattern is that the things that I want to go to the first variables are the grouped things (they are surrounded ...
-1
votes
0answers
23 views

How to extract domain name with regex? [duplicate]

I'm new with regular expressions and trying to figure out how to extract domain name from url list, using regular expressions. At the moment i have: a = open("urls.txt", "r") for line in all_urls: ...
-1
votes
2answers
24 views

Extracting all rows that matches a “pattern” from a range

I'm very new to this and I've googled about regex and RE2, but little help is found. Seems to be rather niche topic and the material isn't quite comprehensive. Would appreciate any help in this. Thank ...
2
votes
1answer
20 views

Substitute variable amount of numbers by it's sum

I need to find a way to substitute n numbers in square brackets, only if these brackets are next to each other, by the sum of these numbers in square brackets; e.g. A[5][3]B[1.5]C[2.3][-1.3][5] ...
1
vote
1answer
26 views

named groups in regex not working as expected

I'm trying to use named groups in regex to reduce the size of the regex. However, even in its simplest form and after clearing all the 'noise', I cannot get it to work. When I try the example in the ...
1
vote
1answer
31 views

How to replace 3 same characters with one in Hive sql?

I'm trying to replace 3 same characters with one i Hive sql. I tried such regex: regexp_replace(first_name,"[(\w)\1\1+]", "\1") and in the result nothing changed. Aaabbb-->Aaabbb I want to have ...
1
vote
1answer
24 views

Replace specific char from regular expression in VS Code

I have this regex: ([A-Za-z])\'([A-Za-z]) This works, is for example for words like : d'utilisateur (in fr) This regex select the d'u but I just want if the condition is met, select only '. I don'...
1
vote
1answer
25 views

groovy regular expression difficulty

I have a string like this: 1R12 or 2EURO16. First character is 1 or 2 (numeric) Middle is a letter or a word (R,L,X,Y,B or EURO) End is 10,12,14,16 (numeric) What I tried is this: (^1|2)(R|L|X|Y|B|...