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
2
votes
1answer
16 views

Replace chars but exclude the word which is using it regex

I'm working on a problem where for example there is a sentence: "Today _asf was a null_word day__and __bla__bla". What I would like to get is a sentence where all: _ are replaced with space except in ...
0
votes
0answers
11 views

Unable to use pyperclip and regex to search for a pattern?

While this seems very sketchy, I am doing this for my MGMT288 class, and am trying to create a program that searches for a SSN from a group of copied text. I have very little python background, and am ...
0
votes
0answers
11 views

regex strawberry perl (windows) one-liner to fix multiple linefeed (0a) characters

In Windows, a report from MS SQL server comes to me with embedded duplicate line feeds that cause errors when reading into LOAD DATA INFILE in mySQL in a Windows environment. I fix this using three ...
-1
votes
2answers
26 views

Regex - Match strings defined by quotes and separated by commas [duplicate]

I need help setting a regex that can separate some strings from some commas. This is the regex I have so far: (?<string>(?<=")(?:[^""\\]|\\.)*(?="))|(?<comma>\,) The idea is to group ...
1
vote
1answer
23 views

Regex: find string between curly brackets, which itself contains curly brackets

Suppose a string on the following format: Use \hyperlink{aaa}{apple {pear} banana} and \hyperlink{bbb}{banana {pear} {apple}}. I want to extract: \hyperlink{aaa}{apple {pear} banana} \hyperlink{bbb}...
-1
votes
2answers
21 views

Java or Python regexp search of large list of words

I have an list of "Nw" English words that I would like to search using "Ne" different regexp's. Nw is several hundred thousand entries, and Ne is several hundred. The regexp's allow only individual ...
2
votes
2answers
21 views

Python split string on dot followed by whitespace [duplicate]

I have a string that contains dots as end of line dots, which were followed by a whitespace and dots belonging to a descriptive word, which has no whitespace after it, like this sample with a date: ...
-2
votes
1answer
43 views

how to get float as well as int from a python string

for key in x: if(key=='data'): dd = dd.from_dict(x[key]) dd = dd[:5] for row in dd.iterrows(): y = str(row) m = re.findall("\d+\.\d+|\d+",y) print(m) I am trying to ...
0
votes
4answers
38 views

Bash select valid rows from file with awk

I have a large data set with some invalid rows. I want to copy to another file only rows which start with valid date (regex digits). Basically check if awk $1 is digit ([0-9]), if yes, write whole ...
0
votes
2answers
24 views

Regular expression to split a string (which contains newline characters) into equal length chunks

I have got a string let's say Test Subject\r\nTest Comments... I want to write a regular expression which would split the string to chunks of n characters say n=6 and the split process should not be ...
0
votes
1answer
40 views

How keep number in text

I have a pyspark Dataframe, I would like to improve the regex bellow. I want to add a condition or modify the regex to: recover all number that is attached to a / or letter in the end. Example of ...
1
vote
4answers
43 views

Extract interger value from string PHP

I have string value like: $string =' 10822|~0-0 10827|~0-0 10990|~0-0 11538|~0-0 11365|~0-0 11517|~0-0 11256|~0-0 11183|~0-0 15554|~0-0 18877|~0-0 ...
1
vote
1answer
54 views

C++ standard regex difference between std=c++11 and std=gnu++11

There seems to be a difference in regex behavior when comiling code using regex and gnu extensions. The following code produces an exception when compiliing with -std=c++11, however -std=gnu++11 ...
0
votes
0answers
39 views

Replace double quotes with graves in a string without creating a new string

I have a json in which I store a property with a link. I want to write this to a .txt file so I can copy the content and use it in a resource object which has a serverUrl variable that I want to ...
1
vote
1answer
26 views

Regex to check Optional Group of numbers

i am trying to create a regex which should be able to accept the following strings proj_asdasd_000.gz.xml proj_asdasd.gz.xml basically 2nd underscore is optional and if any value follows it, it ...
0
votes
0answers
11 views

priority of one pattern over another [duplicate]

I am new to writing regex and I have been struggling on one of them in particular - I would greatly appreciate your help! I am trying to get place/people name that come after 'at' or 'with', such as ...
3
votes
2answers
28 views

NotePad++ regex remove words with space and certain letters

I'm trying to remove words that feature a "com" and ends with a ".". I would like to remove the full word and leave the "." Here is an example of the starting text: This is a test testcom. I would ...
1
vote
2answers
26 views

Regex alternative to negative lookahead

I want to match all paths that include the keyword build unless they also contain .html Here is a working regex that uses negative lookahead: https://regexr.com/4msck I am using regex for path ...
1
vote
1answer
33 views

Regular expression exclude matches surrounded by quotation marks and lines starting with %

I want to make a regular expression that is able to do the following: Match various words exactly, e.g. {addpaths, addpath, test} Exclude lines that start with a % sign Exclude matches that are ...
0
votes
2answers
46 views

(hello-> h3o) How to replace in a String the middle letters for the number of letters replaced

I need to build a method which receive a String e.g "elephant-rides are really fun!". and return another similar String, in this example the return should be: "e6t-r3s are r4y fun!". ( because e-...
0
votes
0answers
29 views

Convert String to Regex, split it in pattern & flags and validate the regex

I have an input where I can add a regex in the form of a string. For eg: ^abc/igm My requirement is: I need to validate the input and check if its a valid regex or not. I need to convert the valid ...
0
votes
0answers
14 views

RegEx to restrict the number of UTF-16 code units for an XSD file

I'm working on an XSD file for XML files that need to be sent to a legacy system. This legacy system has field size restrictions specified in # of UTF-16 code units. For example, the field ...
4
votes
4answers
82 views

What's the best way to turn these nested strings in prefix notation into tuples?

I would like a general solution to transforming strings that are in prefix notation into tuples. Here are three examples below that illustrate what I hope to achieve. Each string is an element in a ...
0
votes
0answers
19 views

Dart regex html extraction prints nothing [duplicate]

I am trying to make a Regex pattern that will get anything within the <body></body> tags in some html. I have made a small example of what I have tried: void main() { Iterable<Match&...
0
votes
0answers
18 views

Regex fails to match cookies and (sometimes) referer

Here's my config: map "$http_cookie" $myVar { default 0; "~*([\\x|%](3c|3e|5c|22|27))+" 1; } location ~ \.php { if ($myVar = 1) { return 500; } My request (using Postman) ...
-1
votes
2answers
62 views

Java: Get all Strings using Regex

I'm trying to get all the strings from a javascript script, I created a code, but it's not catching all, it's skipping some My Code String Strings; public String GetStrings(String str){ ...
0
votes
1answer
25 views

search and replace with regex to increment numbers in Visual Studio Code

I'm currently working on a big svg sprite. The diffrent images are always 2000px apart. What I have is: <g transform="translate(0,0)"> <g transform="translate(0,2000)"> <g transform="...
-5
votes
0answers
39 views

Need a Regular expression for FQDN [on hold]

I need a Regular expression that could validate FQDNs, File path, and IP address: \MT-SLO-X004\Share \MT-SLO-X004.slo.company.corp\Share C:\temp\share So far, I have tried two Regular expressions ...
0
votes
1answer
28 views

Search and replace with particular phrase

I need a help with mass search and replace using regex. I have a longer strings where I need to look for any number and particular string - e.g. 321BS and I need to replace just the text string that I ...
0
votes
3answers
23 views

Regex to fetch value from string

can you help me out to fetch some value from this string which is below ldn2spc2.ebrd.comDiskUtilization-D(Disk) --> Disk Utilization 100 > 95 %(threshold) I want to fetch the drive letter ...
1
vote
0answers
33 views

Prevent emojis in input on all devices

I have an input where I want to prevent the user to write emoji. I already have a regex matching emojis. But when I try to apply it to my code, it's not working: const inputs = document....
1
vote
1answer
28 views

capture the number iwth comma or dot with regex

I have regex code https://regex101.com/r/o5gdDt/8 As you see this code (?<!\S)(?<![\d,])(?:(?!(?:1[2-9]\d\d|20[01]\d|2020))\d{4,}[\u00BC-\u00BE\u2150-\u215E]?|\d{1,3}(?:,\d{3})+)(?![\d,])[\...
0
votes
0answers
17 views

Valid regex for capturing routes with id

I am using Express-JWT to let through all routes with a given ID, that is /api/v1/hub/track/1, /api/v1/hub/track/2 etc should be let through. My function is as below: return expressJwt ({ secret, ...
-1
votes
1answer
32 views

How to write Regex for pattern like a series of Number and String pair separated by Space. Pattern -> n <space> string

Consider a pattern: 7 "Fault" 6 "Reserved" 2 "Running" 1 "Cranking" 0 "Stop" I want to write a Regex for building a key value pair using number as the key and string next to it as Value. So for ...
-6
votes
0answers
44 views

Parsing multiple Json data objects and merging into a single json object in Python

I have string containing multiple jsons I want to convert that string to single json object For example, let the input will be as follows: input = " { "a" : { "x":"y", "w":"z" } ...
1
vote
1answer
18 views

Is it possible to find as much matching words from different sentences located in different columns in Google Sheets?

There are sentences in column A and B. I'm trying to find which sentences have the most matching words and return that sentence from column B. +-----------------------+-----------------------+-------...
-3
votes
0answers
23 views

Replace two values inside .xml using replaceregexp

Multiple file contains this lines: <sample>IF( TEXT( $User.ABC_USR_Brand__c )=&quot;Maruti&quot;, &quot;/servlet/servlet.FileDownload?file=12467abc&quot;, IF ( TEXT($User....
-1
votes
0answers
25 views

Need a regular expression to validate FQDNs(specific FQDN), IP address and filepath at same time

I need a Regular expression that could validate FQDNs, File path, and IP address: \MT-SLO-X004\Share \MT-SLO-X004.slo.company.corp\Share 121.111.22.111 c:\Folder\ I have tried using ([a-zA-Z]+://[^...
-4
votes
2answers
45 views

Get height and length using regular expression

I have a string. GB-1210 40W x 80 1/4L x 30 1/4H I need to get width, length and height from this string using regular expression. Using this regular expression, I can find width But I cannot ...
-3
votes
1answer
19 views

Need to filter value from string which can have dynamic number with text after that using regex [duplicate]

I want to filter value from string which should result me a number followed by text. For example string looks like "There are 9 steps in the house which can be used to visit first floor". Output :"9 ...
-2
votes
0answers
15 views

Need help to prepare a regex for conditional statement

Unable to get the groups of parenthesis for nested conditional statements. I am having a string formula that may contain nested if statements. The single expression is like that if(conditional, then,...
1
vote
0answers
25 views

Trying creates a regex for identify some pattern of vb6 code, functions call

I need to identify a patter of all types vb6 code when functions will called. ^(?:(?!\bDim\b).)*(?:(?<functionName>(?:fl|fg)[a-zA-Z_0-9]+)(?:(?!\s\=\s).)*$(?:\(?.*\)?|))$ Samples flProcessar =...
0
votes
1answer
18 views

Freemarker replace method with regex

im trying to parse a text containing and tags to and tags, i tried: varWithText?replace('style=&quot;&quot;', '') but this left with an space in the tag and i need to get rid of this, ...
1
vote
3answers
61 views

Why my code not working? to find a word before the match

s = 'A boy is playing and he is wearing shirt.' My regex is ((?:\S+\s+)\bis\b) My output: ['boy is' ,'he is'] Expected output: ['boy','he']
0
votes
2answers
35 views

Test if a digit occurs 'x' amount of times with a regular expression

Is it possible to write an regular expression which checks if a given digit occurs x amount of times? I am trying to use the following code to determine if in a given string (of 16 digits), there are ...
4
votes
1answer
56 views

How to validate the string with only specific letter and number?

I want to validate the string containing characters A, B. X & Y. The character A & B must follow by the number but X, Y should not be. // correct "A11X", "A45YA1X", "A1XXA999YYA1", // Not ...
-1
votes
1answer
18 views

How to get all content between two curly brackets, ignoring those in quotation marks?

I'm currently using the following regex with partial success: /\{[^{}]+\}/g But it fails for this situation: {get('{')} {b} I just want to ignore the { and } when they are between quotation ...
-2
votes
0answers
31 views

replace old YouTube iframe code with new version of iframe code using PHP

I have a bunch of HTML snippets with various youtube links in it. I want to replace these as follows: FROM: <p> <iframe foor="bar" src="https://www.youtube.com/embed/ANYCODEHERE" ...
0
votes
1answer
33 views

Django regex url parsing to calling wrong view

I have a Django 2.2 project (using the rest framework) where I need to call a view function with a url of the following format: /class/students?date=07092019` and I've set up the following url route ...
0
votes
1answer
38 views

How can I repeat with a pattern?

I'm trying to replace certain words with spaces through regular expressions. E.g I have the following code to replace the word "onerror=error=" with a space. String content = "ononerror=error="; ...