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
0answers
2 views

How to perform multiple Regex replacements in sequence from a list of unique items cleanly in C#

I'm trying to find a cleaner way of performing multiple sequential replacements on a single string where each replacement has a unique pattern and string replacement. For example, if I have 3 pairs ...
2
votes
1answer
32 views

Regex Grouping returns no values

I'm trying to get some named groups(X, Y, Z, W, P, R) from a string and I'm having problems getting the output. This is the part of the string that has the info I am trying to extract: [1,1] = ...
0
votes
1answer
36 views

How to split the csv with \n with condition

I have csv and need to split the second column with \n name,address 711-2880,Mankato\n96522\n(257) 563-7401 971-2880,CA\n965\n(01) 563-7401\nNebraska Expected Out name,address 711-2880,Mankato 711-...
0
votes
1answer
21 views

PHP regular expression any kind of letter from any language

I'm trying to create my own routing in php using regex, my example returns true when the name is in latain, but when the name is in arabic returns false preg_match('#^(en/users/(?<name>[\p{L}\p{...
0
votes
3answers
30 views

Regex remove all leading and trailing special characters?

Let's say I have the following string in javascript: &a.b.c. &a.b.c& .&a.b.c.&. *;a.b.c&*. a.b&.c& .&a.b.&&dc.& &ê.b..c& I want to remove all ...
0
votes
0answers
8 views

Why is my regex working fine on sublime text but not working while searching using re.findall even on using escape charaters [duplicate]

I am writing a code to remove all the duplicate characters to once if the characters exists more than twice, i.e in the list of words word_list = ["deep", "partyyyy", "groom", "dooom", "yeahhhhhhhh"]...
1
vote
2answers
33 views

How to search a list of strings and remove all extra characters based on a list of names?

I have a data frame with a list of titles and other info, as well as a corresponding list of names. What I would like to do is extract the names from the titles and add them in a new column ("Players)...
1
vote
1answer
24 views

Require http:// or https:// in beginning of regular expression

My regular expression works great except I want to add the requirement that the url must contain http:// or https:// and my attempts to fix the regular expression breaks it. Any help is appreciated! ...
0
votes
2answers
41 views

How to group_by and summarize multiple variables using regex?

I want to use regex to identify the variable to use to group_by and to summarize my data with one step. I cannot do separately because I have a large number of variables to summarize and the variable ...
0
votes
0answers
8 views

RegEX Avoid All Special Characters with Fixed Length & Number [duplicate]

All viewers, Need you guys help for regex I want regex will avoid all Special Characters & avoid fixed number like 558 at the begaining of the string & string length will be fixed. like if ...
-1
votes
0answers
13 views

Adding a 'g' to multiple instances replacing a url results in broken urls Regular Expression Javascript [duplicate]

The reason this is not a duplicate is because if I add the 'g' variable it then matches inside the link itself, thus breaking the link, giving this result: <a href="<a href="http://urlregex.com/...
-1
votes
2answers
31 views

how to extract part of text using regex on a data frame in pandas

I have a data frame and one of the columns are like this: df = index dosage_duration 0 5 years20mg 1X D 1 2 days10mg 1X D 2 2 days10mg 1X D 3 ...
-2
votes
0answers
10 views

Regular Expression to replace multiple instances javascript [duplicate]

The reason this is not a duplicate is because if I add the 'g' variable it then matches inside the link itself, thus breaking the link, giving this result: <a href="<a href="http://urlregex.com/...
1
vote
1answer
47 views

How to use Regex to find a charecters that isn't between quotes?

I want to write Regex expression using C# to find the first ) character that isn't wrapped around single or double-quotes. I have the following string ("some () test 1", 'some text)', 1235,"",null )...
0
votes
1answer
17 views

Check if string contain standalone 'c++' with regex [duplicate]

So I am trying to find out if string contains standalone 'c++' substring, for example: 'abcabcabc c++ abc abc' should return true but 'abcabcabc c++11 abc abc' should return false. I am trying to ...
-3
votes
0answers
10 views

How do I use Regex to match variations of “Chief [*] Officer” in a string? [duplicate]

I have a bunch of strings in a dataset that have variations of "Chief [SOMETHING] Officer". Examples: Chief Technology Officer Chief Executive Officer Vice President & Chief Security Officer ...
-1
votes
0answers
14 views

Python remove duplicated characters in a given string, except for 'rr' and 'ss' [duplicate]

This is to clean Portuguese data. I need to remove duplicated characters in a given text, but there are some special cases that I need to keep them. For instance, the samples below should be ...
-1
votes
1answer
40 views

Regular Expression question for occurence check :

Check if a number n occurs n times and that too consecutively in a string. For example : String x = "33322" Case 1 : If int N = 3; Check if 3 occurs 3 times consecutively in "33322". Here 3 ...
0
votes
1answer
34 views

C++ regex_replace to clean concatenated decimal numbers

As part of cleaning up an SVG path data string for display, I want to add spaces between concatenated fractional numbers. An example would be "0.1.20" should become "0.1 .20" - basically add a space ...
2
votes
4answers
50 views

Split text but include pattern in the first splitted part

Looks very obvious but couldn't find anything similar. I want to split some text and want the pattern of the split condition to be part of the first split part. some_text = "Hi there. It's a nice ...
-2
votes
1answer
23 views

Regex for a sequence with an optional tail

How to match a sequence with an optional tail of variable length. For the example requiredOptional I would like to have an expression that matches required, requiredO, requiredOp, requiredOpt, ...
1
vote
2answers
34 views

regex to find words in a sentence with no repeated consecutive characters

I am looking for a regex pattern to filter out words in a sentence with no repeated consecutive characters. I have tried r'(?!.*(\w)\1{3,}).+' as the regex pattern but it doesn't work. for instance, ...
1
vote
2answers
51 views

How to use mutate to create multiple variables with regex

I want to create new variables using paste0 by performing operation on other variables also using paste0. My approach fails as it only pastes the names of the new variables as observations, without ...
-1
votes
0answers
14 views

Spring MVC Request mapping using regular expression

Here is my requirement I want to have Spring Controller method to handle below request /download/filename.extention /download/dir1/filename.extention /download/dir1/dir2/filename.extention /...
0
votes
2answers
24 views

How to parse a string of function parameters with REGEX in PHP

I am trying to handle parameters like Java or PHP natively handle them, using Regex to parse variable numbers (and types) of arguments. For example, a function might be: util.echo(5, "Hello, world!");...
2
votes
3answers
20 views

I have written a regex for matching the sub string with spaces around it but that's not working well

Actually I was working on a regex problem whose task is to take a substring (||, &&) and replaces it with another substring (or, and) and I wrote code for it but that's not working well ...
1
vote
1answer
25 views

How to use re.search and groups if sub string exists multiple times after each other

I have the a string looking something similar like that: s = ' A <span class=""latex""> B </span> C <span class=""latex""> D </span> E ... I want to replace the span like ...
-2
votes
0answers
31 views

Regex to select or grep anything that comes between 2 given words [on hold]

Experts, I need to get the output i.e anything that comes between the words 'address' and 'state up' from the given string. String: ltm pool JJB_IMAP { members { 10.128.168.80:epmap { address 10.128....
0
votes
2answers
43 views

How to select first chars with an custom word boundary?

I've test cases with a series of words like this : { input: "Halley's Comet", expected: "HC", }, { input: "First In, First Out", expected: "FIFO", ...
-1
votes
1answer
27 views

Regex and (char)30 How can I define

I have a code. I am using Regex. string s = "1-2-3-4-5" (Instead of "-" there is ctr + Shift + "-" in Office Word) Regex regex = new Regex(@"\d*-\d*-\d*-\d*-\d*"); WordsCount = regex....
0
votes
0answers
10 views

Use Regex To Match Word At Start Of Line Or Preceded By Space

I am trying to match the word "hello" only if it starts at the beginning of a line OR is preceded by a space. So far I have tried: ^|(?<=[ ])hello But that only matches words that come after a ...
1
vote
0answers
19 views

Tokenizing words by preserving certain words with arithmetic and logical operators in python 3?

While tokenizing multiple sentences from a large corpus, I need to preserve certain words as in its original form like .Net, C#, C++. I also want to remove the punctuation marks (.,!_-()=*&^%[email protected]~ ...
1
vote
0answers
19 views

Parse c style nested struct using regex in python

I am trying to parse c struct using python. https://github.com/fox-it/dissect.cstruct/blob/master/dissect/cstruct/cstruct.py#L371 Regex: r'(#(?P<flags>(?:compile))\s+)?((?P<typedef>...
0
votes
0answers
18 views

regular expression contains groups (in no particular order) [duplicate]

how can you look for a pattern that would have occurrence of multiple groups in a string but in no particular order? examples=['on Sunday Jack went to the Gym', 'Mary had a workout on Sunday at the ...
2
votes
3answers
32 views

Regular expression to replace string except in sqaure brackets

Need to replace all forward-slash (/) with > except for the ones in the square brackets input string: string str = "//div[1]/li/a[@href='https://www.facebook.com/']"; Tried pattern (did not work)...
1
vote
1answer
14 views

Regex match last square brackets in SQL Script SSMS

I am trying to perform a regex match in SQL Server Management Studio 2017 to then do a replace on part of a SQL script that looks as follows: ,ISNULL([Gt 01 To 02 Weeks SUM 1],0) AS [Gt 01 To 02 ...
0
votes
1answer
51 views

How to use case_when with loop and regex?

I want to generate a new variable named new_p which takes the values of other variables based on paste0. My approach below produces the new variable, but does not assign the values correctly. It only ...
0
votes
2answers
30 views

Regex to find / remove newlines between frontmatter (---)

Started looking into regular expressions and I know some basics but now I tried to remove category and subcategory from a lot of Jekyll markdown files using regex. I succeeded to remove the two ...
-7
votes
0answers
31 views

i want to add banner left and right [on hold]

how can i add responsive banners on both sides, image or gif https://betdeals.uk/
0
votes
0answers
13 views

How to determine wifi hardware address in Termux

I need to determine my device's MAC (hardware) address, ie that for the wifi. I'm using Termux on an Android device, although maybe an answer will apply more generally. I'm using python, but any bash ...
0
votes
0answers
27 views

Need help from regex guru with complicated matching [duplicate]

I've spent some time on this problem but really need help from a regex guru. So far I have the following which doesn't quite give me what I need. \[.*?\]\s[=><]+\s[\@]\w+ From the following ...
-1
votes
0answers
15 views

Find multiple words in Regex multiple times [duplicate]

I want to find 3 words which are in text document using Regex and these words should be there at least 2 times anywhere in text. But I do not know how to write it down in Regex, do you have any idea ...
1
vote
1answer
61 views

How do you combine the lazy quantifier “?” with the number of occurences {x-y}? [duplicate]

(This is part of a coding challenge, I have to use only one regular expression to solve this problem. I can't not use regex or remove the duplicates after) I have a JSON string that contains a bunch ...
-1
votes
2answers
35 views

Javascript regex throwing syntax error in edge [duplicate]

I have a simple regex I'm using and that works perfectly in chrome but edge throws a syntax error, ths is the line : var html=text.match(/^<div.+\/div>$/ims); I don't see the problem.
-5
votes
3answers
58 views

Regex to allow only Numbers, alphabets, hyphens - up to fixed length [on hold]

I need a help here for regex pattern to allow only Numbers, alphabets, hyphens(-) up to fixed length . my sample input data will be as below. kindly let me know please. Length between each hypen ...
0
votes
0answers
15 views

regex with react router

I have the following paths in my react something/special/value something/special/value?hl=ar something/special/value?hl=ar&some=pop I want my app to have 'value' in the props that i can pass to ...
0
votes
1answer
25 views

REGEX_REPLACE not matching all chars from the beginning to the first occurrence of a 5 digits word

I've this record in a Mysql table: ADDRESS ---------------------------------- sdasd 4354 ciao 12345 sdsdsa asfds I would like to match all chars from the beginning to the first occurrence of a 5 ...
0
votes
0answers
9 views

Nginx Directives not working for url with slash at end

I want to redirect certain matching url to example.com , I have below code location ~ ^/blog(.*)$ { rewrite ^ http://example2.com/$1 permanent; } Above code works fine for http://example.com/...
0
votes
1answer
32 views

Regex expression for reptitive groups

This one is for the regex experts. I am trying to write a Regex expression for a key value pair for Cookies, which has a = in front of key and a ; at the end of the value. So, basically a key=value; ...
2
votes
2answers
36 views

JS Regex lookbehind not working in firefox and safari

I have this following regex which is working in chrome but causes an error in firefox or safari. I need to modify it to make it work. Can anybody help out a poor soul? Thanks in advance! regex: /(?=&...