261,091 questions
-1
votes
1
answer
75
views
JavaScript regular expression behaviour
I have next JavaScript code in a HTML document.
var a="abc=def&ghi=jkl&mno=pqr".split(/(^|&).*?(=|$)/);
alert("0='"+a[0]+"' 1='"+a[1]+"' 2='"+a[2]+&...
-4
votes
0
answers
69
views
ReDoS - Incorrect regular expression [closed]
In ReDoS test the following JavaScript snippet was given the flag.
What could be the fix to eliminate the ReDoS flag?
if (!id || !/^\d+$/.test(id)) return null;
Best practices
1
vote
5
replies
135
views
When is (?(DEFINE) ... ) needed?
In Perl regular expressions, (?(DEFINE)(?<NAME>...)) creates a referencable pattern which can be executed by the "recursion" mechanism e.g. (?&NAME). This is useful if the "....
0
votes
2
answers
101
views
How to avoid that the first capture group is omitted?
I created a pattern in .NET 8 to match and capture only two named groups in a string. I use start and end string anchors to match the whole string. However, it also matches and captures the second ...
-6
votes
2
answers
130
views
Regex nested / recursive pattern [duplicate]
I am trying to decode an encoded string k[encoded_string] to k * encoded_string. So, I am looking at using regex to accomplish this.
How to construct a regex pattern which has nested / recursive ...
-1
votes
0
answers
175
views
Python re search all multiline blocks in text
I have a text with SQL queries from which I want to extract all the SELECT blocks:
sql_que = """
select p.value_n, p.enabled from proper p;
select p.value_n, p.enabled
from ...
-6
votes
1
answer
191
views
Connecting 2 regular expressions doesn't work
I'm trying to work out a match with 2 similar regular expressions.
First one:
(constraint\s+\w*)*primary key\s*((on\s+conflict\s+\w*)*\s*(autoincrement)*
Second one:
(constraint\s+\w*)*primary key\s*(...
Tooling
0
votes
1
replies
92
views
something like regex style textbox validation in css
Is there something like
div:regex('some regex'){
color:red;
}
or
#error_message{
display:none;
}
There could be textbox validation done using regex in CSS. Textbox could be found using CSS like ...
0
votes
4
answers
274
views
Multiple search-and-replace inside the same text
I need to move some chunks of text around in a file. I am partially successful, in the sense that I can move only the first chunk successfully.
The text in the file looks like this:
text regtext1 ...
-1
votes
3
answers
139
views
how can I regexp match a string containing only isolated instances of a character among other characters?
I have a string like this...
20260317_104524__CL2418942__SOC_PM_DF_CSTATE_REGR__df_cstate_regr__df_umc_nbio_hubs_pcie_msub_\_.xml
... and I want to pluck out the bold part (SOC_PM_DF_CSTATE_REGR).
...
0
votes
3
answers
129
views
Using a regex lookahead after spaces
I am trying to write a simple script to process JSON5 — the idea is to convert to standard JSON and let JSON.parse() do the rest. I’m using regular expressions to do the conversion.
One part is to ...
-1
votes
1
answer
133
views
Regex Named Capture Group also Include Complete String
Is it possible to have a Regex include the whole string as a named capture group as well as individual named capture groups?
I am trying to parse IIS logs and can successfully extract the details I ...
Best practices
2
votes
1
replies
137
views
Text search versus regular expressions
I'm doing text search with user entered queries against multiple sources documents.
The user can enter 16 MB or 16MB and the document can contain one or the other. I could not make it with pure text ...
Advice
3
votes
11
replies
248
views
Integer Partition Regex
I need to construct a regex given an integer n that matches any partition of n with a leading +. For example, if n=10, it should match +10, +9+1, +1+9, +1+8+1 etc.
Since there are only finitely many ...
0
votes
2
answers
93
views
Replace regex with Jinja2
I use Jinja2 and mixhtml for validating length of the input from the user.
From my app.py two cons
USER_USERNAME_MIN = 2
USER_USERNAME_MAX = 20
But I'm not sure how to place them into the input ...
Best practices
0
votes
18
replies
482
views
How programmers really finds out which 'regex' is required for their solution?
I often struggle to decide which regex pattern fits a requirement. How do experienced programmers approach designing regex? Do they memorize common patterns, build them step by step, or rely on ...
0
votes
3
answers
147
views
RegEx Find all words that are NOT in line with a starting Single Quote
This will be used in a Classic ASP (VBScript) project.
I am trying to find the words that are NOT in line with a starting single quote.
Regex example of finding all words.
(\b(CreateObject|Set|Open)\b)...
4
votes
4
answers
273
views
Modify numeric values with Perl one-liner
I would like to use a Perl one-liner to modify numeric values in a text file. My data are stored in a text file:
0, 0, (1.263566e+02, -5.062154e+02)
0, 1, (1.069488e+02, -1.636887e+02)
0, 2, (-2....
2
votes
1
answer
106
views
Dataweave how to use variables in regular expression
I want to use a regular expression in Mulesoft Dataweave and substitute some values by using variables.
I have this code which excecutes fine in Dataweave:
"1000000087" replace /^(.{3}).(.{6}...
1
vote
2
answers
219
views
How to dynamically repeat the replacement string per match with PHP's preg_replace() [duplicate]
We have a capture group of Z, and we want to display this capture group X number of times using regex in PHP.
I can not find a working syntax for this. For example:
This captures the "Z" 5 ...
6
votes
4
answers
146
views
Why do negative lookbehind and optional group allow a match?
I have a regex where a negative lookbehind and an optional group is producing a match when I'm not expecting it to. There appears to be something about their interaction that I am not understanding, ...
Advice
1
vote
6
replies
100
views
How to match any amount of Unicode characters (letters, numbers, surrogate pairs) in regex?
How to match any amount of Unicode characters (letters, numbers, surrogate pairs) in regex:
😆
ẘ😆
😆😆
ẘaሴ
abc123
I am looking for an equivalent to /^(\[a-zA-Z0-9\]+$)/i that finds ASCII.
Best practices
2
votes
4
replies
75
views
How to parse informal Persian number words into an integer currency value (Rial)
I need to convert informal Persian user input that represents a monetary amount into a single integer value in rials in python.
The input is free-form and may include:
Persian number words (e.g. یک, ...
1
vote
0
answers
113
views
Mongo driver C# is always using global flag for regex
I have a generic function to always query my mongo collection with a limit and get the entire result in a single batch.
I noticed the queries with Contains and StartWith were taking longer than ...
0
votes
1
answer
124
views
How to parse tab delimited header based on multiple header lines with spaces in R
I am working with older weather data files with a 3-line header. The first line identifies the station, the second provides column names, and the third gives the column units. The problem is that ...
0
votes
2
answers
144
views
How to exclude subtotal lines from result
Invoice contains services and Subtotal rows:
Internet_Usage 1058 187822_MB 1 000 000
PhoneCalls 48 02:42:39 2 000 000
Subtotal 3 302 5998
Parking 8 4 000 000
Subtotal 4 302 5998
sum is third number ...
1
vote
4
answers
113
views
SAS prxmatch how to deal with searching for a " within the middle of the expression?
%if %sysfunc(prxmatch(/^\("([A-Za-z])"\)$/, %str(&names))) = 0 and %upcase(&stringC) = N %then %do;
%put ERROR: Please format as such ("obesity","diabetes&...
Advice
2
votes
6
replies
94
views
How to get the expansions from a glob pattern to use in another path
The Problem
I want to create a function in Python for finding and moving files where I can specify a glob-style pattern to find source files, and then a second pattern to describe where to move them ...
Advice
2
votes
6
replies
67
views
Powershell and -replace regex against blank lines '^$'
I like powershell's features, but not a big fan of MS Powershell documentation and supplied examples.
An internet searching for this kept coming up with how to remove when I wanted to replace empty ^$ ...
0
votes
1
answer
152
views
How to avoid "Not a HASH reference at ..." in regex like "qr/^${\CONSTANT}{3,}$/"
In a script I'm using constants (use constant ...) to allow re-use ion actual regular expressions, using the pattern from https://stackoverflow.com/a/69379743/6607497.
However when using a {...} ...
Advice
0
votes
12
replies
6k
views
Generate Regex based on Input String and also known output
I have an input string like example/123/2457 and I know the expected output would be 2457. Is it possible based on the above information to generate a regex so when that would be applied on the input ...
0
votes
3
answers
300
views
PHP, $regex to obtain each URL of videos about $pattern
I try with some regex to obtain only the URL of all the videos about $pattern but my $regex not work (in this case $pattern = "Greta"):
$data = '<p><a href="https://www.youtube....
1
vote
3
answers
233
views
How to use regex in R to shorten strings by one space
I have some old data files with a large number of writing errors. An example is attached below, where some of the numbers in the .dat file are 9 digits or characters long rather than the expected 8.
...
2
votes
2
answers
142
views
Valid regular expression pattern validation in XML
I have a string element in an XML schema that I would like to restrict to the extended Latin character set plus numbers, punctuation, whitespace, etc.
I have tried the following:
<xsd:pattern value=...
4
votes
2
answers
198
views
Regex - How do I check for digits 01 to 52 in filenames?
I have found the answer :-)
It is: ^ghf(0[0-9]|[1-4][0-9]|5[0-2])\d{3}[A-Z]{2}_v\d{2}.pdf$
I receive filenames from a client that are structured according to the following scheme:
ghf50001BE_v02.pdf
...
0
votes
4
answers
173
views
Reducing indentation of specific lines within 1 cell based on contents within line
Incoming with another VBA question.
I'm currently have data within a column that has many line breaks, but certain lines need to be only indented 2 spaces whereas certain lines need to be indented by ...
-1
votes
3
answers
109
views
sed outputs matching line twice
I want to delete all lines that end with OFF except if they contain override.
Input
1765193089 socket override DiningRoom/Socket/Work/state ON
1765206025 socket evening Hall/Socket/Lantern/state OFF
...
-4
votes
3
answers
246
views
Captures all domain names within a property SubjectAlternativeName
I’m trying to extract a specific portion of text and haven’t had success despite testing multiple patterns and looking at similar examples. After struggling for a while, I figured it was time to ask ...
2
votes
2
answers
188
views
Troubleshooting: A single regular expression matching nested braces usable for java and perl
I have a regular expression in an extension of java by florian ingerl
to parse a latex command,
\\\\DocumentMetadata(?<docMetadata>\\{(?:[^{}]|(?'docMetadata'))*\\})
but the important thing is ...
-2
votes
1
answer
151
views
How can I solve this problem of test difference?
As far as I understand, the difference between expected and actual one is NBSP (Non‐Breaking Space).
I don’t know how to remove this. It doesn’t get highlighted and cannot be found using CTRL+H (...
-2
votes
2
answers
160
views
Detect srt blocks that contain exactly one dash (-) using regex [closed]
I’m working with .srt subtitle files in PHP and I need a regex that finds blocks containing exactly one dash (They're regular hyphens (-), not minus signs) and it starts at the beginning of a line.
...
4
votes
1
answer
111
views
Regular Expression Complex Matching
I'm working on a php project and I need to extract some informations from strings like :
COROLLA CROSS (07/22>09/25<)
I tried different patterns without success, such as:
preg_match("/(?P&...
1
vote
1
answer
105
views
Excluding allowing apostrophe in regex doesn't work [duplicate]
I have this method:
func isNameValid(_ value: String) -> Bool {
let trimmed = value.trimmingCharacters(in: .whitespaces)
guard value == trimmed else { return false }
guard trimmed.count ...
0
votes
1
answer
122
views
Regex - basic string replacement
I have a string which may or may not contain a code for an emote, all of which begin the same: "auroraa1"
Such as:
"auroraa1Smile", "auroraa1Bye", "auroraa1Love&...
Advice
0
votes
8
replies
154
views
Match a string not preceded by a pattern
I want to match a string according to a pattern but only when it is not preceeded by an other pattern.
const source = "abc.def.Ghi\n\
@:test(abc.def.Ghi2)";
const re = /(?!\()([a-z]\w+\.)+([A-Z]\w*)/g;...
5
votes
2
answers
186
views
Hex escape sequences in bash regex range have no effect
Here is a bash script:
#!/bin/bash
char=$'\x01'
if [[ "$char" =~ ^[\x01-\x20\x7F-\xFF]$ ]]
then
echo "Unprintable"
else
echo "Printable"
fi
The script ought to say ...
-1
votes
2
answers
127
views
Force sumif() with wildcard and fixed pattern
I have a Google spreadsheet with the following values:
+------------+-----------------------------+
| G | F |
+------------+-----------------------------+
| Hours (G)...
-2
votes
1
answer
114
views
How to access named capture groups in C++? [duplicate]
On Regex101, I have simple Regex with a named capture group in ECMAScript flavor:
(?<name>.*)
I'm trying to do the same thing in C++:
#include <iostream>
#include <regex>
using ...
1
vote
2
answers
154
views
Replace a long case statement involving regex with a hash
I'm parsing a number of text files of different formats. Some are csv, some are xml and some even txt. I have a case statement that checks if a certain string is contained in the first 100 bytes of a ...
Best practices
0
votes
4
replies
143
views
How to search through Unicode text with ASCII input in Python
I have a corpus of text which includes some accented words, such as épée, and I would like people to be able to easily search through it using ASCII input. Ideally, they would simply type protege or ...