Skip to main content
The 2024 Developer Survey results are live! See the results

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.

-1 votes
0 answers
14 views

Replacing a sentence that has citations in a DOCX file as Track Changes

I trying to replace a sentence instead of old one (which has citations) in a DOCX document using OpenXmlRegex.Replace method. The thing is creating the regex of old sentence and using it for replace ...
-1 votes
0 answers
14 views

Perl Why is this lazy regex acting greedily? [duplicate]

my $file = '/a/b/c.xxx'; my $path = $file =~ s'/.*?$''r; print "$path\n"; $path = $file =~ s'/[^/]*$''r; print "$path\n"; The second substitution gives what I was expecting a/b ...
0 votes
0 answers
9 views

pwsh7 URL regex help needed

I am working on a powershell core 7 script, running in Windows environment. Requirements of the regex: Three or Four part host addresses The last two parts can be one of two options: specificPartA....
56 votes
1 answer
18k views

Is it possible to type-hint a compiled regex in python?

I would like to use autocompletion for a pre-compiled and stored list of regular expressions, but it doesn't appear that I can import the _sre.SRE_Pattern class, and I can't programmatically feed the ...
0 votes
2 answers
36 views

Get href value between two substrings [duplicate]

I am trying to capture the following pattern: <a href="http://cdn.xyz.com/media/info.pdf" target="_blank"> This is what I am trying: preg_match_all( '/(<[a-zA-...
0 votes
2 answers
64 views

Get ALL-CAPS word and time expression from predictably formatted string

I need some help with extracting 2 pieces of information from the following string: viewed MUI slideshow (00:01:45) I need the MUI and the time, without the parentheses. viewed and slideshow will ...
0 votes
0 answers
11 views

Pyspark Regex Lookbehind Beginning Of String [duplicate]

My string in column "Key" is: "+One+Two+Three-Four" I want to extract all words following the "+" sign: df.select(regexp_extract_all("Key", F.lit(r"(?<=...
1 vote
1 answer
23 views

Is there any situation where re.search could not be used instead of re.match? [duplicate]

The documentation seems clear but it begs the question, what is the purpose of re.match? Couldn't re.search with the caret (^) be used instead as long as the MULTILINE flag is not enabled? Is re.match ...
-1 votes
1 answer
54 views

How to search for and highlight matching text/phrases within the entire document-body's text-content?

I want to regex and replace only text content(innerText) of an html, and in the end keep all the HTML elements (or restore them as they were). The regex must not check the HTML elements, but only the ...
1 vote
1 answer
77 views

Get substring between two substrings [duplicate]

I have a string and I want to extract out some information for it. The string could be like this $string = "Followers: abc.com. ID by: [email protected]. More info: all the rest of information goes ...
61 votes
7 answers
17k views

Finding a DOI in a document or page

The DOI system places basically no useful limitations on what constitutes a reasonable identifier. However, being able to pull DOIs out of PDFs, web pages, etc. is quite useful for citation ...
0 votes
2 answers
42 views

Parse multilingual flight info logs and extract potentially space-separated flight numbers

I have data like the following <terminal:Text>1 #VS 5 J9 C9 D9 I9 Z9 W9 S9 H9 LHRMIA 1235 1705 744 0E</terminal:Text> <terminal:Text> K9 Y9 B9 R9 L9 U9 M9 E9 Q9 X9 N9 ...
1 vote
1 answer
51 views

Removing string between two specified strings in Python 3 [duplicate]

I am working on an NLP project that requires me to remove computer code from a piece of text. The code is encased between the tags <pre><code> and </code></pre>. Now I could do ...
0 votes
2 answers
2k views

Get value from square-braced key=value placeholder in text

I want to get a value from a placeholder in a string. $string = "blah blah blha lorem ipsum [get_this_value=10] more lorem ipsum"; I would like a function that returns "10" as the ...
1 vote
3 answers
196 views

Parse string containing square-braced path keys and key=value expressions and make a multidimensional array

I am going to parse a log file and I wonder how I can convert such a string: [5189192e][game]: kill killer='0:Tee' victim='1:nameless tee' weapon=5 special=0 into some kind of array: $log['5189192e'...

15 30 50 per page
1
2 3 4 5
17374