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.
73
questions
0
votes
1
answer
18
views
Converting this preg_replace to match a word with a plus
In PHP I need to highlight multiple given words in a string, for example wrapping found matches inside a <em> tag.
But if I have a word ending in + I cannot do it.
I understand the below problem ...
-1
votes
0
answers
20
views
Perl Why is this reluctant regex acting greedily? IE In what circumstances does .*? match more than the minimum [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
1
answer
16
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....
0
votes
0
answers
12
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"(?<=...
0
votes
1
answer
27
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
0
answers
17
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
1
answer
36
views
Bookmark Lines Between Two Regex Patterns in Notepad++ Without Including the Patterns Themselves [duplicate]
I have a list, and here is an example snippet:
Newii
27,807,147
Supd
26,518,465
Ns.
26,175,538
Mai
24,930,812
Gas
0623,901,055
TEim
20,213,631
Tes
GrV
18,968,412
Mytyttyst
y
htththt
hyhyh
October 2013
...
0
votes
1
answer
18
views
Read Response body and assign into one variable in JMeter
I need to read authId value from below response returned by one of the Http Request item in JMeter and assign into in one variable under JSON extractor . "Should I use $.ApiResponse.data.authId&...
-1
votes
0
answers
17
views
Regex unicode categories \p{L} combined with a Python formatted string [duplicate]
I would like to write a regular expression in Python that is a formatted string and includes a unicode category.
The regex would look like this:
import regex as re
mystring = "abc"
m = re....
2
votes
1
answer
36
views
Bookmark last comma-separated value before specific separator using Notepad++ regex
I have a list of text data formatted as follows:
Drtyjtyjnt
11,825,222
Ftyryer
8,823,623
Strtrtuperd
8,542,448
Ts
7,153,156
Supd
7,122,304
Su.3
6,920,743
Supld
dddd
tgtgtg
Sd
April 1991
///////////////...
0
votes
1
answer
50
views
Regex not matching group at the end of the string, even though $ is included
The string format is similar to:
1) some question text
A)option
B) option
C) option
D) option
2) some question text.
A) option
B) option
C) option
D) option
etc.....
0
votes
0
answers
26
views
Select2 ajax based results filtering based on regex on client and server side
I have implemented select2 in codeigniter for ajax based results and its working perfectly. But the challenge I am encountering is that the data in database is not sanitized e.g
E.C.G Machine
ECG ...
1
vote
2
answers
55
views
Append to a line only if regexp is found
I have the following Ansible code:
---
- name: skip fail2ban in iptables checkmk plugin
hosts: localhost
gather_facts: no
tasks:
- name: modify plugin
ansible.builtin.lineinfile:
...
0
votes
1
answer
28
views
"if regex.test" doesn't works properly on javascript vuejs router [duplicate]
const router = createRouter({
history: createWebHistory(),
routes,
});
// ...
const allowedToAnonymous = [
/^\/login$/g,
/^\/signup$/g,
/^\/home$/g,
/^\/emailconfirm\/[0-9a-zA-Z]{8}$/g,
...
0
votes
1
answer
53
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
0
answers
10
views
Non-word characters in SHAP's default tokenizer
My basic question is: why are the non-word characters making it into my SHAP output, and how do I prevent it?
I am applying SHAP to a black-box machine learning model fn_predict_proba() (the model ...
-4
votes
0
answers
48
views
Why is using regex group feature on Python giving different outputs? [duplicate]
import re
string1 = "aaabaa"
zusuchen = "aa"
#1
m_start = re.finditer(fr'(?=({zusuchen}))', string1)
results = [(match.start(1), match.end(1)-1) for match in m_start]
for z in ...
-3
votes
0
answers
54
views
Getting text from a string [duplicate]
I am using this pattern below
<a href=.*##ENCLICKTAG##2104.*\s*<\/a>
To extract the first "a" tag content from this String below
<a href="##ENCLICKTAG##2104&&...
0
votes
1
answer
41
views
Detecting OR operator sequences and wrapping their content in a parenthesis when building a query with PHP
I made the following PHP code to build a query based on user input, where they can choose the condition and the operator and the resulting query would be printed on their screen every time they added ...
-1
votes
0
answers
27
views
Bash Regex Start Anchor w/Character Classes Not Working [closed]
GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
$> var=39Q08a
...
-1
votes
0
answers
11
views
query in elastic using regular expressions
I want to find the value of quality:0.60 from elastic using kibana. I have a log field containing the following text inside
1721901536 [01;30mDEBUG [00m tracker.cpp:92 [01;30mTracker[bf19311e0d65] ...
-1
votes
0
answers
22
views
Splicing Relavent Text from a Screenshot using pytesseract and ocr for Scheduling script
Hi I'm currently making a script that can take screenshots of a university class schedule and automatically sync it to either google calender or outlook calendar.
from PIL import Image
import ...
0
votes
1
answer
28
views
Issue retrieving City/State/Zip line from block of text
I have a bunch of blocks of text that will contain address information such as:
Fake Name
Business name
60 N Address Ave.
San Jose, CA 95126
(555)255-5555
Email: [email protected]
I need to ...
-1
votes
1
answer
56
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 ...
0
votes
0
answers
31
views
Can I serve a git repo and html from the same URI?
I have a small static website, generated by a script which I want to distribute along with the source data. Thus if I make a hook which runs git update-server-info, the HTML will be at https://example....
1
vote
0
answers
26
views
Malformed CDATA in xml
I get a XML from a third-party service,
This one is malformed sometimes CDATA tag aren't close,
My goal is to write a regex capable of catching only malformed CDATA,
example :
<Couleur_regroupement&...
1
vote
1
answer
46
views
How to extract the volume from a string using a regular expression?
I need to extract the volume with regular expression from strings like
"Candy BAR 350G" (volume = 350G),
"Gin Barrister 0.9ml" (volume = 0.9ml),
"BAXTER DRY Gin 40% 0.5 ml&...
0
votes
1
answer
38
views
Regex to match lines followed by another Line
I'm working with a text input and i need a regex pattern to capture lines that are followed by another line. Specifically i want to match lines that end with exactly one newline character and are ...
-1
votes
0
answers
30
views
What are subtle cases when implementing regex grouping translator?
The following code is based on the book code base in MIT 6.5151 course.
Here "translator" means the code transforms the Scheme specific function into the POSIX regex expression.
This ...
3
votes
0
answers
30
views
Regex works in regex101 but not in VSCode - How to fix? [duplicate]
I'm trying to use a regular expression in Visual Studio Code to match a pattern in my text. The text is as follows:
Cat
AAAAAAAAAAAAAa
Dog
Cat
BbbbbbbbbbBbb
Dog
I want to match everything from "...
0
votes
1
answer
23
views
Truncate or trim a subdirectory path string to an arbitrary number of characters with regex
I have a text file of several thousand URLs that I need to truncate or trim with regex. I am using BBEdit as a text editor as it has a great regex find/replace function.
This is an example of one of ...
1
vote
1
answer
40
views
How to use replace text using a regex in a Pandas dataframe [duplicate]
I have the following dataset:
meste = pd.DataFrame({'a':['06/33','40/2','05/22']})
a
0 06/33
1 40/2
2 05/22
And I want to remove the leading 0s in the text (06/33 to 6/33 for example). I ...
1
vote
2
answers
20
views
In google sheets, how do I compare a cell to a range of regular expressions
I have a column that contains a number of different regular expressions, like this:
Regex Patterns
^abc
^def
^ghi
...
^xyz
I have another column with some strings:
Strings
abc123
def456
I ...
-2
votes
0
answers
19
views
matching nested two-part patterns [closed]
I am processing various text strings to extract parameters and values for use in a 'parameters' table. These strings vary in size and complexity, so it's not like I can expect a consistent syntax. ...
-1
votes
0
answers
7
views
Match urls starting with http and end with a domain using regex [duplicate]
I have a very large string where it might contain 'http' urls from 'mysite'. I want to match instances of these urls.
I tested the following regular expression to match the urls /^http:\/\/(.+?)mysite....
1
vote
1
answer
41
views
Datadog Regex is not replacing the right data
I am using Datadog Sensitive Data Scanner to redact some sensitive data from my logs. Datadog Sensitive Data Scanner supports Perl Compatible Regular Expressions (PCRE).
Example of a line of log:
...
1
vote
0
answers
42
views
Regex that allow alphanumerics, spaces, dots, hyphens, but not an empty string
I have this REGEX in Java that alllow simple short sentences with alphanumerics, dots, hyphens and white spaces:
Pattern MAX_LENGTH_30_NO_SPECIAL_CHAR_ = Pattern.compile("[A-Za-z0-9\\s\\-.]{1,30}&...
1
vote
1
answer
40
views
Regx pattern for Pyspark: match start and middle of a text and extract the middle
I have text in a pyspark column called TEXT that look like below:
The sky is red. I have 2 apples and I am fine.
----------------------------------------------
The sky is back. I have 8 apples or I am ...
-4
votes
0
answers
35
views
JavaScript Validation regex to allow only alphabet text or alphanumeric only [duplicate]
I need Javascript validation regex to allow only alphabet text or alphanumeric only.
Example -
dGgs1s23 - valid
12fUgdf - valid
abchfe - valid
ABFGC - valid
121232 - invalid
abd()* - invalid ...
-2
votes
0
answers
31
views
Regex code to read out coordinates from a single line [duplicate]
I have a string from which I want to read the coordinates for the X axis.
Here my String:
G74X106.5Y-49.Z-22.6P1800Q51000F0.28R0.1
Here what i like to get:
106.5
In addition, the whole thing should ...
1
vote
1
answer
36
views
How to parse pdf in r and then correctly convert or extract spaced/tabbed pieces of text into columns of dataframe?
I am reading a pdf in r using library(pdftools)
library(tidyverse)
library(pdftools)
library(lubridate)
pdf_rowwise <- strsplit(pdf_text("V://path//sample.pdf"), split = "\n")
...
2
votes
1
answer
27
views
Match list of host in mongo query doesn't work
I have below query :
mydb.my-collection.aggregate([
{
$match: {
$and: [
{timestamp:
{
$gte: $__timeFrom,
$lte: $__timeTo
}}
...
3
votes
1
answer
60
views
Parsing formulas efficiently using regex and Polars
I am trying to parse a series of mathematical formulas and need to extract variable names efficiently using Polars in Python.
Regex support in Polars seems to be limited, particularly with look-around ...
2
votes
1
answer
51
views
How can I expand a regex to find the entire URL in these cases?
I need to match complete blogger.googleusercontent.com image link URLs that include the /img/a/ subdirectories. The URLs are for images, and the file names don't have file extensions, but that may not ...
-4
votes
0
answers
36
views
regex is failing in first char itself [closed]
^[^\s][\/s]*[A-Z0-9][A-Z0-9\.\,\:\;\/\-]*$
above is regex if i enter M it is failing or does not match.
what changes i can make in above regex?
1
vote
2
answers
60
views
How to extract or capture the value from stdout_lines of an Ansible playbook?
I am looking for help to extract or capture the free MB value from the stdout_lines of an Ansible playbook execution and use that value as a criteria to proceed further in the playbook.
My task output ...
-1
votes
2
answers
58
views
Add space after specified data using regular expression in Visual Studio
As we all know, Visual Studio has very powerful text editing functions. Now there are hundreds of thousands of data in my txt file. I made a wrong operation, which caused some problems with the data.
...
3
votes
1
answer
55
views
python regex to get text within a pattern defined
I'm working on writing a parser to extract information from the output given below
i need to get all the three texts which are in between '--'. so i wrote a regular expression as below
import re
def ...
0
votes
1
answer
54
views
vuejs @input is getting called only after onfocusout, i want to call it when user is typing
i am trying to use @input on input field in vuejs, but the function assigned to it gets called only after user has stopped typing and the focus is out of the input field, that means it is getting ...
0
votes
0
answers
102
views
Issue in masking AccountNumber and CreditCardNo in a free text field [duplicate]
Please re-open the question as scenarios mentioned below are different than the ones which are in linked question. I am awaiting answer from @bobble.
I am having issue in masking the below strings. ...