Skip to main content

Questions tagged [regex]

Regular expressions provide a declarative language to match patterns within strings. They are commonly used for string validation, parsing, and transformation. Specify the language (PHP, Python, etc) or tool (grep, VS Code, Google Analytics, etc) that you are using. Do not post questions asking for an explanation of what a symbol means or what a particular regular expression will match.

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

Extract Main Domain from URLs in PostgreSQL Without Subdomains, Ports, or Query Parameters

I’m working with a PostgreSQL query where I need to extract the main domain (including the second-level domain and top-level domain) from URLs. However, the current approach using REGEXP_MATCH or ...
sci9's user avatar
  • 744
3 votes
2 answers
46 views

Python/Regex: Finding a specific pattern to update and then placing it back in the original text

I have a long file containing thousands of lines and a couple of samples are shown below: \begin{align*} H_0 \amp : \mu_1 = \mu_2 = \mu_3 = \mu_4 = \mu_5 \\ H_1 \amp : \text{Some text} \\ H_2 \...
M. Al Jumaily's user avatar
2 votes
2 answers
52 views

output repeating and non repating digits using regex from s = '1222311'

I am finding it difficult to write regex expression. Need your help in getting expected output. import re pattern1=r'(\d)\1{1,}' s = '1222311' c=re.finditer(pattern,s) for i in c: print(i....
quora question's user avatar
2 votes
0 answers
15 views

Extracting text from cloudwatch

I have a cloudwatch message format as follow: POST /api/v1/order 200 123 bytes 456 bytes 458.000 ms Apache-HttpClient/4.5.14 (Java/17.0.12) { "orderId": "A123" } {"...
vincentsty's user avatar
  • 3,165
0 votes
0 answers
14 views

Unable to print 2nd occurrence from rates [duplicate]

My sample text is pretty simple $56K - $86K (glass My regex is [0-9]+K which prints both 56K and 86K but I just want to print out 86K i.e. the 2nd time it matches the regex. I have tried the ...
Vik G's user avatar
  • 619
1 vote
1 answer
38 views

How to Parse a field with Pattern “userid-date-amount” in postgresql

I’m working on a query where I need to parse Description field that follow the pattern “userid-date-amount-” For example, a valid value would be: 222826-2022/07/26-32,700,000- However, my current ...
sci9's user avatar
  • 744
2 votes
3 answers
58 views

Regex: Find matches only outside of single quotes

I currently have a regex that selects all occurrences of (, , , );: (\s\()|(,\s)|(\),)|(\);) however, I've been trying to figure out a way so that if anything is between single quotes 'like this, for ...
RadicalRaccoon's user avatar
-2 votes
0 answers
34 views

concatenate string comprising specific text + changing pattern [closed]

I have dataframe like this: df <- data.frame(ID=1:4, text = c("From Roman times until the middle of the 18th century, the new year was celebrated at various stages", "Every day the ...
RLoseR's user avatar
  • 9
0 votes
0 answers
15 views

How do I extract map key-values from a json in sumologic?

I've gone through the sumologic documentation but I can't figure out how do I extract map key values from sumo logic. so I've a json that looks like this { "eventType": "DummyEvent&...
rafat islam's user avatar
0 votes
1 answer
35 views

Regular expression to check for potential isograms C#

Suppose I need to write a method to look for non-repetetive characters (hyphens and whitespace characters are allowed to be met more than one time in an input): public static bool IsIsogram(string ...
Anthony Voronkov's user avatar
1 vote
2 answers
35 views

Run 2 transforms on 1 snippet in VSCode

I want VSCode to generate my classname based on my filename: Filename: test-class-file.php should become: Test_Class_File I found the following examples: "${TM_FILENAME_BASE/[-]/_/g}" ...
janw's user avatar
  • 6,654
2 votes
2 answers
79 views

Test for Unicode properties on older versions of Perl

Unicode adds new properties to the Unicode database and these are added to later versions of Perl. I'd like to be able to est if a property is allowed on my current version of Perl. I have tried perl -...
JGNI's user avatar
  • 3,973
2 votes
4 answers
75 views

Grouping text with regex

consider I have a text like : Some text 1 `special text` Some text 2 I can get "special text" with regex, but I want other parts of the text too as an array, something like this : [ Some ...
Ehsan Hatefi's user avatar
0 votes
0 answers
29 views

Why `.*` get an extra matches in js/python/perl but not in awk/sed/R? [duplicate]

When I replace .* with another string using regex, I got the following result: In Linux sed, awk and perl: echo -n 123 | sed 's/.*/456/g' 456 echo -n 123 | awk '{gsub(/.*/,"456");print}' 456 ...
FaniX's user avatar
  • 148
0 votes
0 answers
31 views

Why is QValidator not working with the mask

The validator and the mask I set seem to conflict somehow. The validator and mask are to manage a line edit, to have a HH:MM format. The mask giving the : and the validator to ensure a real time was ...
Luck y's user avatar
  • 1
0 votes
2 answers
58 views

Regular expression to extract monetary values from an invoice text

I have a regular expression: \b[-+]?(?:\d{1,3}\.)(?:\d{3}\.)*(?:\d*) (Python) that matches numeric values in strings like this: Amount: 12.234.55222 EUR Some Text 123.222.22 maybe more text 1.245.455....
user3793935's user avatar
1 vote
1 answer
42 views

Matches the same two digits that were captured in the first group

select * from bha b where b.bks similar to '\d{2}[A-Z](\d{2})\d\\1'; The purpose is to regex but bks is in the form 12A56856 12A12812 12A898389 Although I already have this data in my database, ...
Nguyễn Tuấn Hưng's user avatar
-2 votes
0 answers
25 views

Inefficient regular expression [closed]

allowedString = /^(\w+ ?)*$/ This part of the regular expression may cause exponential backtracking on strings containing many repetitions of 'a'. CodeQL is complaining of this expression. What ...
lahari edulla's user avatar
1 vote
0 answers
32 views

How can searches too-large-for-regex be performed in DataTables in an R Shiny app?

I need to search a specific column in a DataTable for such a large number of terms that the table.search() using regex doesn't work. All of my search terms will either match exactly or not at all. Is ...
tomato_soup's user avatar
0 votes
3 answers
92 views

unable to solve a question on validating a string using regex in python

These are the conditions: It must start with a 4, 5 or 6. It must contain exactly 16 digits. It must only consist of digits (0-9). It may have digits in groups of 4, separated by one hyphen "-&...
rushi's user avatar
  • 17
1 vote
2 answers
57 views

Regex doesn't match subgroups as expected

I am writing a C program that makes use of regex to detect a string like: hl # # # Where # indicates an integer. Up to 11 integer values should be captured here I have written the following regular ...
Dennis 's user avatar
  • 1,125
1 vote
0 answers
34 views

Why doesn't regular expression /£?.*£?/ match string '£45.56–34.90' in PHP 8.2? [duplicate]

I'm using PHP 8.2.11 on Mac Sonoma 14.5. My code is: $cost = '£45.56–34.90'; $matches = array(); $found = preg_match( '/£?.*£?/', $cost, $matches ); I'd expect preg_match() to return 1, ...
pandammonium's user avatar
0 votes
0 answers
6 views

301 bulk redirects using Redirection WP plugin (RegEx option)

I need to redirect a large numbers of similar URLs to a single URL. For example: Source: https://www.domain.it/parent1/page-name1, https://www.domain.it/parent1/page-name2, https://www.domain.it/...
Marco Chisari's user avatar
1 vote
1 answer
56 views

Regex in python to split sentences by full stop (dot / period character) but ignore abbreviations and dates which contain full stop?

I want to search for a keyword in the text and to extract each sentence which contains the keyword. When extracting each sentence, I want to ignore full stops (meaning periods or dot characters) in ...
Martina Nacheva's user avatar
-2 votes
0 answers
21 views

How to write a Regex to match nested HTML tags in a Java application? [duplicate]

I am working on a Java application where I need to process HTML content. I need a Regex that can match nested HTML tags correctly. Here is an example of the HTML content I am working with: <div> ...
nikhil2050's user avatar
1 vote
1 answer
33 views

Regex for inner tag detection

I have a document generation application that handles tag replacement, I use a regular expression to detect said tags. These tags can be of multiple types, for the sake of the problem let's take into ...
Filipe Nóbrega's user avatar
-2 votes
0 answers
19 views

Regex for string with at least one digit AND at least one letter [duplicate]

I want to find with regex all occurences of a string (allowed letters and numbers) with at least one digit and at least one letter, with length between 6 and 9 (inclusive). Samples: My passport number ...
Michal.Jan008's user avatar
0 votes
1 answer
23 views

How do i automate a gitlab runner setup using ansible?

Problem: I'm working on an Ansible playbook to manage GitLab Runner registration and configuration. The playbook should: Register a GitLab Runner and extract its token and ID. Template a config file ...
duesmile's user avatar
1 vote
2 answers
58 views

Make a word optional between a negative lookbehind and a target word

This regex (?<!not)\s(hello\W*world) will not match when hello world is preceded by not word. How do I make it not match too when there's a word in between: not a hello world? I'm trying this regex ...
kyw's user avatar
  • 7,265
-1 votes
0 answers
19 views

Need RegEx to check Exactly 8 letter string (including special chars) that accepts atleast 1 alphabet & 1 digit : without lookahead assertions ((?=)) [closed]

Need a RegEx to check Exactly 8 letter string (including special chars) that accepts atleast 1 alphabet & 1 digit : without lookahead assertions ((?=)) Example: @#$3%g&J I have the below regex ...
HiGL's user avatar
  • 1
0 votes
0 answers
42 views

Extracting Arguments from Function Calls with Regular Expression

Problem Formulation I have to extract arguments from function calls with NodeJS. For example: `foo0()` => [""] `foo1(1)` => ["1"] `foo2(1, "HelloThere")` => [&...
imakak's user avatar
  • 308
0 votes
2 answers
73 views

Regex Pattern to Mask Field with Commas in Java [closed]

I am working on a Java application that processes strings. I need to mask the content of a specific field. The challenge I'm facing is that this field sometimes contains commas, which interferes with ...
Amna Zahid's user avatar
-1 votes
1 answer
65 views

How to use a regex group and backreference to verify file contents

I have a file with timestamps and want to verify the contents. Two lines within the file should have the same timestamp value (but the value changes from run to run). I want to verify that whatever ...
jwrey01's user avatar
  • 17
1 vote
2 answers
49 views

Extracting a numeric value from the middle of a String field in MS Access 2016

Our department uses a Microsoft Access database to manage roughly 300,000 records. The front-end of the system allows users to add comments to a donor's record. As you might guess, the comment field ...
Tim O's user avatar
  • 33
-1 votes
1 answer
31 views

Regex grafana variable

I am using grafana variables to bring some data, but the data comes with '%20' that I need to remove using regex, I have tried many times without result, the data has this form: PSM%20APP%20ST%20 PSM%...
Avellino's user avatar
-1 votes
0 answers
34 views

Enforcing character limit in Regexp [duplicate]

I'm currently working on a fairly simple email validation pattern, but I'm unable to cap the local domain part of the pattern to 63 characters. The restraints of the pattern are that there should be: ...
HJEC's user avatar
  • 450
-7 votes
0 answers
60 views

What would be the regex for this date-timestamp "2024-07-09T23:53:16.6632713-04:00" [closed]

I am trying to perform a regex search on this date-timestamp but it is not working. I have tried this REGEX: ^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]+)?([Zz]|([\+-])([01]\d|2[0-3]...
Avijeet Deb's user avatar
0 votes
1 answer
33 views

Extracting an ID from a filename that is optional and happens before a special character [duplicate]

I have a regex that parses filenames extracting an optional ID and a product name. It only works partially and I wonder why that is the case and how I would fix this. The files look like this (...
Christoph Rettinger's user avatar
0 votes
1 answer
21 views

RegEx for 3 characters and 7 numbers with no special characters [duplicate]

I am still learning to do regex, but this one gets me stumped for a while. I am trying to make a regex expression to match the strings like TOL1234567 or tol1234567. There should be 'TOL' at the first ...
deafprogrammer24's user avatar
-1 votes
0 answers
12 views

Regex atom that refers to the end of the current regex pattern(parenthesis enclosed detection) [closed]

Look ahead from two different points in the pattern might be another valid way to formulate it. I'd like to condition the parsing of e.g. () parenthesis and I'd like to detect whether something in ...
Mike's user avatar
  • 1
-1 votes
1 answer
27 views

REGEX expression for XML tag in NetSuite saved search

Hope someone can assist here. I have a LONG TEXT field which holds the extract of a XML file. I want to be able to report on this field inside a saved search, extracting the value of the 'Country' tag....
Arif WB's user avatar
  • 316
0 votes
0 answers
48 views

Powershell file tailing with pattern matching, output truncated

I'm tailing file and, if a string match my pattern, I want to output the match in a text file. Everything works but, the output is truncated. What am I doing wrong? $MyMatch = "(\A.{21})(.*?)(...
ilRobby's user avatar
  • 81
-2 votes
2 answers
35 views

Oracle regexp_replace entire matching word

Input: ABC DEF GHIJ123A KLM GHIJ456B RST UVW GHIJ789C Ouput: ABC DEF GHIJ000X KLM GHIJ000X RST UVW GHIJ000X So, I want to find all instances of words in the string that start with GHIJ and replace ...
Vani Narayana's user avatar
-2 votes
1 answer
25 views

Regex matching online but not in App Script for MMM-YYYY [duplicate]

This is my Regex Pattern to match Date format MMM-YYYY(Apr-23). I have checked this on Regex101 it works as expected. (\b\d{1,2}\D{0,3})?\b(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:...
Tpk43's user avatar
  • 377
-1 votes
0 answers
26 views

Is there php redirect function that will be redirect if match referer only? [closed]

I try like following but it doesn’t work in sometimes. <?php $refer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null; if( preg_match("/anysite1/i", $refer) or ...
user2971638's user avatar
-2 votes
0 answers
26 views

add double quote delimiters to a tab separated file in notepad++ [closed]

I have a tab separated file where I need to add double quote delimiters around the text fields. Not all the text fields start with a letter, some start with numbers. There are also number and date ...
DMC's user avatar
  • 1
1 vote
1 answer
34 views

VBA Backreferencing using Regular Expressions Find and Replace

I want to standardize the formatting of some text within a Word document using VBA and regEx. For example, my document would contain text strings such as "Qty #", "Qty (#)", "...
Carter Roekle's user avatar
0 votes
0 answers
19 views

RegEx - String contains specific verbiage [duplicate]

I am new to RegEx, but I am trying to setup a process that sets a designated 'Role' based on an employee's title. For instance, I have a list of key phrases that point to the user having a role of '...
J J's user avatar
  • 11
0 votes
2 answers
64 views

Return the sum of all the numbers contained within the string

Instructions: The sumNums function takes a string as an argument. It should return the sum of all the numbers contained within the string. If there are no numbers in the string, sumNums should return ...
Primary Maths Worksheets's user avatar
1 vote
0 answers
18 views

Regex - lookahead and between [duplicate]

Suppose I have this structure of strings. I have >100k. 'xxxxxx0AxxZZxxBBxxxxx1AxxxxxBB' --Group1 is 1 'xxxxxxxxx0AxxxxZZxxxxx1AxxxxxBBxxxx' --Group1 is 1 '...
Henrik Løv's user avatar

1
2 3 4 5
5209