Questions tagged [regex]
Regular expressions provide a declarative language to match patterns within strings. They are commonly used for string validation, parsing, and transformation. Because regular expressions are not fully standardized, all questions with this tag should also include a tag specifying the applicable programming language or tool.
239,322
questions
0
votes
0answers
3 views
Convert article with references to html with modal box
I have article with references:
Text[1]
[1]
[11]
[12,2]
[13,13]
[14,15,16]
and I want to convert to HTML. I need to match numbers individually and put them into Capture group 1. I will replace every ...
0
votes
0answers
9 views
regex doenst work only by words that end with -> str
my regex doesnt work propeply, i want to replace all words that end with -> str.
but only words that end with not when a word is only -> str.
word -> ABCstr. <--- i want to replace
word -...
0
votes
0answers
5 views
I can't match using ansible lineinfile regex with two fields and a dollar sign beginning second field
Data:
mydestination $myhostname, localhost.$mydomain, localhost
Ansible snippet:
- name: Add domain name
ansible.builtin.lineinfile:
dest: /etc/postfix/main.cf
regexp: '^(mydestination =) ($...
0
votes
0answers
10 views
markdown table regex for html format content
I am adding markdown feature in my project.
In my case i can't use innerText value. Because, If some manipulated content are already there that's also getting collapsed. So, I want to find out ...
0
votes
0answers
22 views
Remove spaces using regex in Python
I have a long string which consists of sentences where some words are embedded with HTML tags, something like so:
House prices <b>declined</b> <b>in</b> Canada <strike>&...
0
votes
1answer
16 views
Using R Regex to identify two characters followed by a dash and two numbers
Very obnoxious regex question incoming! I have a column that I am trying to split into two based off a condition. I'd like a new column to be created when there are two characters, followed by a dash ...
-1
votes
0answers
13 views
Javascript Regex to ReplaceAll with Specific Characters and Unspecific Numbers
Is it possible to use Javascript to replace a certain part of a string (using replaceAll) with another string when part of the string is dynamic?
For example,
s = "A sentence [number]123321[/...
0
votes
0answers
20 views
Recursively iterate to validate pattern
I am trying to do regex validation on a string to ensure it matches a pattern.
Pattern is <n>...</n> however my recursive validation breaks as we go deeper into the recursive tree.
var ...
0
votes
0answers
15 views
Remove all posible symbols(emojis etc.) except of text php & js
My test website has a feedback form. There are 2 required fields. From the line, I remove all emoticons and leave one text. And to check for the length, I'll remove all the spaces as well. Most ...
0
votes
0answers
11 views
Regex Document section
I'm trying to split out document section from a document and I can not get the regex quite right.
Example:
1.2 Some text
1.3 some text
c.1.2 some text
B.1.2 some text
Result:
1.2
1.3
c.1.2
B.1.2
All I ...
0
votes
1answer
21 views
Regex to add a span around a word but not in the href of a link
I'm trying to add some styles to words in a post, this works okay but when I have a url the link breaks because the key word is in the href. For example, I want to add styles to the word website:
If I ...
0
votes
0answers
18 views
Change conditional variables to become specific dataframe
i have a several "similar variables" but it has different label's number and year categories. I would like to make them as dataframe that sequential with my label's number and year from top ...
0
votes
0answers
24 views
Remove leading whitespace before HTML tags in Python using regex [closed]
I have a long string which consists of sentences where some words are embedded with HTML tags, something like so:
House prices <b>declined</b> <b>in</b> Canada <strike>&...
0
votes
0answers
7 views
Regexp to replace chars keeping the first two characters [duplicate]
I need a help to replace all chars(except the first two) in a string with *, keeping the string length.
Ex:
Rafael -> Ra****
Robertson -> Ro*******
0
votes
3answers
26 views
What regex should i use for this split?
I have this String:
" < 2, 3, 4 >"
and i want to split in order to have an array like this:
["2", "3", "4"]
The "<" character can have ...
0
votes
0answers
10 views
Workaround for negative match of string in RE2
Is there any workaround for negative match of string in RE2? Like ^(?!.*(term 1|term 2).*?), but working in RE2.
Expression ^[^term]*$ matches all strings without characters t, e, r and m.
Background: ...
0
votes
0answers
25 views
How to substitute vowels with apostrophe “a'”, “e'”, “i'”, “o'”, “u'” instead of accented vowels ('à','è','ì','ò','ù') of names contained in an array [closed]
I have an array in PHP like this:
$array_names = array ("Nicolò Gargiulo", "Luca Nisticò", "Sandro Muscarà", "Silvia Sbingabù");
and I want to change all the ...
0
votes
0answers
15 views
How iterate until there is no more inner tags remaining [closed]
I am trying to do regex validation on a string to ensure it matches a pattern.
Pattern: <n>...</n> however it gets more complicated since it can have nested patterns.
E.g.
1) INVALID: ...
-1
votes
1answer
37 views
How to loop though a array and run regex on each element in php
This is my array new array that I want to loop through
$burger = ["beef","chicken","turkey"];
This is my current if statement but its just for one hard coded option ...
0
votes
1answer
20 views
Filtering Django data by dictionary and regular expression?
I was trying to combine filtering Django data through a combination of dictionary and regular expression. So my dictionary looks like this:
dict = {key: r'.*?' + value + '.*?$'}
where I have key and ...
0
votes
1answer
16 views
Filter string with non-English character in Python
I have this list for example
items = ['www1bmobạnk.com', 'наш-переславль.рф', 'вольттек.рф', '別邸福の花浜松町店.com', 'благовест.рус', 'թարմլուր.հայ', '피시방.com', 'ått.com', '沃華科技.com', 'впамяти.рф', '...
0
votes
0answers
16 views
Regex { } curly brackets arn't working in Python [duplicate]
Im about half way through the "Automate the Boring Stuff" book, but I've reached a problem.
import re regexHa = re.compile(r'(Ha) {3}') regexHa.search('He said "HaHaHa"')
Whenever ...
0
votes
0answers
7 views
Google Analytics - Match URLs on Unique Number in Content Drilldown Using RegEx?
I am trying to track pageviews on Google Analytics for knowledge base articles (on Zendesk).
Each article has a unique number. However, the title of the page is sometimes appended to the URL, and GA ...
0
votes
0answers
7 views
Remove certain pattern from string with Python [duplicate]
I have this string:
String with 2 links. This is [link u=234af2-234d]link number 1[/link] and this is [link u=2sdf234-a]link number 2[/link].
and want to remove everything between the square brackets....
-1
votes
0answers
25 views
Adapt a regex for POSIX without lookarounds
In Python I'm using the following regex:
rgx = r"(?<!while )it is(?= )"
In order to replace it is with that thing is as in the following examples:
while it is foo, it is also bar ...
-2
votes
0answers
18 views
How can I use regex to replace sentences with an inconsistent pattern?
I'm working on a text cleaning project and could really use your help.
My dataset contains many variations of a sentence that I would like to remove. The beginning and the end of the sentence is ...
0
votes
2answers
17 views
how to structure iterating through a list based on a condition in Python?
I am reading a PDF and saving elements to a list. I need to get names and dates using regular expressions. I'm good with regex but wondering about how to logic this.
As I iterate through a list (each ...
0
votes
1answer
29 views
How to replace several parts in a url with a regex?
I am using regex to replace some parts of an URI.
What I would like to do is, for example, in a URI: /something/more/and/continue/123456789/word?l=1
replace /something/more/ by an '_'
replace the '/' ...
0
votes
2answers
24 views
std::regex not matching
I have a regex which by regex101 works correctly:
There are 2 matches, as intended.
Now I'd like to split the same with std's regex_token_iterator:
const std::string text = "This is a test ...
0
votes
2answers
13 views
VS Code Find and Replace across files using Regex to correct error in number of quotes appearing on a particular line
I am trying to use VS Code's (Ver 1.55.2) 'Replace in Files' to correct an error in number of quotes appearing on a particular line across multiple files.
In both the error cases, there is an ...
0
votes
0answers
25 views
Regex a fileshare and copy and paste files from the subfolder level
We have hundreds of clients that are each given a unique identifier. The purpose of my program is to copy and paste files of certain subfolders and ignore other folders. So for instances, the file ...
-2
votes
1answer
18 views
Notepad++ regex deleting certain table rows [closed]
I'm trying to find and delete table rows that have 'noData' as data in Notepad++. Might be a better way to do it, but Notepad++ is a must here. th value can be any string. All of the table (every tr ...
0
votes
2answers
28 views
Regex to remove excess backslashes in python
I've the following text in a list:
text='More Fulham open to offers for Stefan Johansen, Jean Michael Seri and Maxime Le Marchand QPR are keen on Fulham\'s Stefan Johansen who was not included in ...
1
vote
3answers
45 views
Regex to split the first from a “/token1/token2/token3”
I'm pretty rusty with regex, but I have the requirement to extract the first token of the following string:
Input: /token1/token2/token3
Required output: /token1
I have tried:
List<String> ...
-4
votes
0answers
17 views
Regular Expression [closed]
Regex : Account For Which Logon Failed:\s*.*\s*Account Name:\s*(.+?)"
Result : Account For Which Logon Failed: Account Name:Test123 Account Domain:aaa Account Name:xyz"
Above Regular ...
-4
votes
0answers
28 views
How to find an extra word inside a string with PHP [closed]
This is currently what I have tried but still not working.
if(preg_match("/\bstella 1 x\b/", "stella 1 x")) {
<td align="right" width="50%">_</td>
}
...
-1
votes
1answer
21 views
Regex - How to validate mathematical equation like (\lim_{h \to 0} \frac{f(a+h)-f(a)}{h}) in kotlin?
I am working on a math formula rendering app that needs to validate a math input from the user and convert it to equivalent Math image format.
I did tried with ^([-+/*]\d+(\.\d+)?)* but later i ...
1
vote
1answer
24 views
pandas.str.findall() returning multiple instance of the same value but with reduce characters
so I am having trouble with Pandas for a series findall(). currently I am trying to look at a report and retrieving all the electric components. Currently the report is either a line or a paragraph ...
-4
votes
0answers
15 views
How to read and replace some strings in xml file using python
I have been trying to replace some text after reading an xml file, after reading the file, i want to replace some part of it with a string in a variable.
This is what I'm trying to achieve, I'm still ...
0
votes
1answer
24 views
Regex match two strings with given number of words in between strings
I want to match characters including and between two strings. (for a given number of words acceptable between them)
For example:
text = 'I want apples and oranges'
Parameters are 'apples', 'oranges' ...
0
votes
1answer
14 views
Regex expression to find a match based on two strings regardless of sequence
I need regex that can find matches based on two strings. The strings can be in any sequence and may not be next to each other.
This is functional but I was wondering if there is a smarter way:
(...
-3
votes
0answers
17 views
I have an error with assignment 4 in Introduction to data science in python in coursera [closed]
import pandas as pd
import numpy as np
import scipy.stats as stats
import re
nhl_df=pd.read_csv("assets/nhl.csv")
cities=pd.read_html("assets/wikipedia_data.html")[1]
cities=cities....
-2
votes
1answer
26 views
Extract the 5 highlighted data points from content using regular expressions using c# [closed]
INDIA, August 25, 2020—Private exporters reported to the U.S. Department of Agriculture export sales of 20,000 metric tons of soft red winter wheat for delivery to unknown destinations during the 2021/...
-3
votes
0answers
11 views
Unable to find matching pattern to RE from different files using OS.walk
I RAN THE BELOW CODE. I'D LIKE TO EXTRACT JUST PHONE NUMBERS FROM MULTIPLE TEXT FILES(FROM THEIR TEXT CONTENT) IN A FOLDER. NOT SURE WHATS WRONG WITH THE BELOW CODE. NO ERROR AS SUCH. IT DISPLAYS THE ...
0
votes
3answers
36 views
Regex for a string with multpile test cases
I am trying to figure out a specific regex for a string that may result out in a different format:
Example:
"Fluid 13.4"
"Fluid 13.4 gm% fluid_haemo 12.0-14.0"
"Fluid gm% 13....
-1
votes
1answer
23 views
Regex - How can I take everything between the second and third comma?
I have the following string:
"4w4190,UK,value,,another data,,job,1,,23"
I want to remove everything before the second comma and everything after the third comma.
The result should look like ...
1
vote
2answers
40 views
Speed up and simplify multiple if/else with regex machers
I have Scheme based lips interpreter written in JavaScript, and inside the parser I have single function for parsing the values. Inside S-Expressions:
function parse_argument(arg) {
var regex = ...
1
vote
1answer
30 views
How to extract the first letter and the following three digits from a string using regex java
I have strings like
S103FYUN031800644100
5S103LKAAN031801261400
32S103AKJA031804534600
From the above strings, I have to extract the bolded part from each of the above strings using regex, anyone with ...
-2
votes
0answers
22 views
Validate parameter based on regex pattern in SQL [closed]
I want to pass parameter value from one procedure to another. So parameter value should be in particular format
e.g. 111fa85f64-5717-4562-b3fc-2c963f66afa6
Parameter value say EventID must match this ...
-3
votes
2answers
53 views
looking for a regex pattern to remove contents in a json string
I have a json string something similar to below
string
str=[{"name": "Dukes","lastname":"Chavez","salary":"10000","clearingbankAccinfo&...