Questions tagged [regex]

Regular expressions provide a declarative language to match patterns within strings. They are commonly used for string validation, parsing, and transformation. Since regular expressions are not fully standardized, all questions with this tag should also include a tag specifying the applicable programming language or tool. NOTE: Asking for HTML, JSON, etc. regexes tends to be met with negative reactions. If there is a parser for it, use that instead.

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

Regular expression with negative lookahead failing in XSD [duplicate]

I'm trying to validate a restricted string using a regular expression ... <xs:simpleType name="myStringType"> <xs:restriction base="xs:string"> <xs:pattern value="^urn:...
0
votes
5answers
33 views

Replace only if “.” is the only value in a data frame column in python

I have a data frame that I am working with where missing values are specified with a dot (".") and I'm trying to replace the missing data with "Not_Given". However, some other columns have "." within ...
1
vote
1answer
15 views

Populate df row value based on column header

Appreciate any help. Basically, I have a poor data set and am trying to make it more useful. Below is a representation df = pd.DataFrame({'State': ("Texas","California","Florida"), ...
-2
votes
0answers
13 views

PHP regular expression with lowercase, underscore, and numbers [closed]

I want a regular expression that must start from 1 to 8 lower case letter (no numbers), followed by an optional underscore, and after underscore 0 to 5 optional numbers. /[a-z]{1,8}_?[0-9]{0,5}/ ...
0
votes
2answers
30 views

Writing a function to extract integers from strings using regular expressions

Trying to Write function integers_in_brackets that finds from a given string all integers that are enclosed in brackets. Example run: integers_in_brackets(" afd [asd] [12 ] [a34] [ -43 ]tt [+12]xxx"...
-6
votes
2answers
42 views

Regular expression for only one pair of brackets

Every string which contains only exactly one pair of brackets where "(" comes before ")" is a valid string. Valid: abc(abc)abc ()abc abc(abc) () \n() Not Valid: abc (abc ( ) abc(()abc abc(ab())abc ...
0
votes
1answer
16 views

If statement fails with regex comparison

public list[str] deleteBlockComments(list[str] fileLines) { bool blockComment = false; list[str] sourceFile = []; for(fileLine <- fileLines) { fileLine = trim(fileLine); ...
0
votes
1answer
29 views

Empty regex returns and repetitions

I am trying to retrieve some content from a csv, am converting the list objects to strings, and then am attempting to use regex to reduce a bunch of strings to repetitive parts (eventually to count ...
2
votes
2answers
27 views

Regex Capturing Group

Say I have this dummy URL and I need to extract plants and their colors as capture groups https://flowers.com/compare._plant1.green.402992_plant2.yellow.402228_plant3.red.403010_plant4.orange.399987....
0
votes
0answers
43 views

Separate/Group plain text with Regex and PHP

I can separate data from the plain text below with Regex. Plain text: 190.A 42-year-old male patient has been delivered to a hospital in a grave condition with dyspnea, cough with expectoration of ...
2
votes
2answers
25 views

Match regex with Uppercase

I need to match string that starts with uppercase like A, BBB, C, Cela, BLE. Just the upper case is important. Trying out I reach this result \^[A-Z]\w+\gm but the thing is I'm getting the correct ...
0
votes
2answers
35 views

How to select the list of words containing a particular substring as part of a SQL query (oracle)?

I'm trying to return the list of "words" (separated by spaces) containing a certain substring within a string as part of an Oracle Sql query. Would like to return the result as a comma separated list. ...
0
votes
0answers
27 views

Comparing two regex expressions for efficiency [duplicate]

Why is: [\s\S]+? Much more efficient than: (?:.|\n)+? What are the differences between the two in terms of how they work behind the scenes? Note: this is with DOTALL turned off. Also, from https:/...
-1
votes
1answer
25 views

Powershell extract data from text file and convert to csv

So I have a text file as shown below. How could I use PowerShell to just grab the mac address and port number(far right column) and output it to a csv file with headers(mac, port)? 1 010D....
0
votes
2answers
26 views

Separating words with Regex (Not in specific order)

Extracting from text For example; the following sentence contains the initial capital letters. How can I separate them? Text: A. lorem ipsum dolor sit B . 41dipiscing elit sedC. lorem ipsum dolor ...
0
votes
3answers
34 views

Removing extra pipes and text around them from string in Perl with regex

Let's say I have a string like this that I'd like to process in perl. hello|world|nice|to|meet|you I'd like to keep the first three pipe symbols and the text around them and discard the rest of the ...
1
vote
4answers
52 views

java regex to capture any number of periods within a string

I am trying to match on any of the following: $tag:parent.child$ $tag:grand.parent.child$ $tag:great.grand.parent.child$ I have tried a bunch of combos but not sure how to do this without an exp for ...
0
votes
3answers
40 views

C# regex string that is not another string

I want to match an at least 3 letter word, preceded by any character from class [-_ :] any amount of times, that is not this specific 3 letter word string2. Ex: if string2="VER" in " ODO VER7" ...
-2
votes
1answer
14 views

Setting that will cause find and find/replace to use regex in Visual Studio Code

I cannot find the setting that will make find/replace to always default to regex in Visual Studio Code.
1
vote
2answers
28 views

How to insert specific character in penultimate index of string with regex

I want to insert a hyphen - in the penultimate index of string. I created a code in javascript using substring() that works: let str = "mystring"; let size = str.length; let lastCaracter = str....
0
votes
1answer
21 views

How to use an altered value of a matched expression as replace value in PhpStorm?

I have some CSV data where I want to de-double quote some numbers. example data ("string", "34", "some other string"), ("foo", 27, "even more strings!"), ("bar", "11", "one more for luck..") For ...
0
votes
1answer
47 views

name splitting in base r

I've got a list of names that have been written in a messy way in a single column. I'm trying to extract first name, middle names and last names out of this column to store separately. To do this, I ...
-2
votes
2answers
44 views

Go Negative LookAhead Alternative

I was wondering if there would be any way to regex match a string that contains qcc but does not have -c following? for example the following two would match: sdfsd/sdfs/d qcc -lang-c++ -...
1
vote
1answer
24 views

How do you split the following vector of strings based on a delimiter that occurs after a certain character pattern in R?

Here is an example of the vector: strings<- (c("SPG_L_SPG_R", "SAS_SPG_R_SFG_L", "s_cere_R_SPG_L" )) I need the split strings to be "SPG_L", "SPG_R","SAS_SPG_R", "SFG_L", "s_cere_R", "SPG_L" I ...
0
votes
1answer
29 views

Match something before a set of characters and until a character in Regex

I'm currently struggling with finding a way to extract domain names in urls. My strings xyz.weam.com we2.wal.com abc.workwork.google.net I would like it to look for (com|org|net) and take the ...
0
votes
1answer
35 views

Replace special character if between any two characters in SQL

I am making a SQL call via PHP to get the following sample data: Item 1: Blaster-Blue,Item 2: Blaster-Red, Extended Mag,Item 3: Kit-Thermal Det, 2" Spanner, Motivator I want to replace any comma ...
1
vote
2answers
26 views

Can a Filter Formula return multiple values?

I have a tracker that when the user puts a "V" in a cell it will populate in another sheet that users name. To get the information I am using this formula =IFNA(JOIN(", ", FILTER(Input!$A$5:$A$30, ...
1
vote
2answers
34 views

regex error: bad character range 8-1 at position 6

I am trying to map a new value based on characters in a column. These are digits stored as a string. If the value of the first character is 1 and the second character is 2-10, then label this as "...
0
votes
1answer
22 views

Regex mach two tags from html sample text at the same time [duplicate]

I have problem with regexp. This is a sample text: <h4>HEADER</h4><p>Test document: <a id="1" linktype="document">TEST DOKUMENT TXT</a>. Lorem Ipsum is simply dummy text ...
-1
votes
0answers
29 views

Why this regex doesn't work in my vb.net code?

I have some strange issue to deal with. I used this site https://regex101.com/ to test my result string. I need to get visitors user-agent string where they visiting my site and then I create small ...
4
votes
1answer
60 views

Golang regex to extract values inside parantheses and ignore inner parantheses in any [duplicate]

I have the following example of key=value pairs as one line string start=("a", "b") and between=("range(2019, max, to=\"le\")") and end=("a", "b") Using regex in golang I want to extract the key=...
0
votes
4answers
53 views

C# Regex to match single number among multiple numbers in a string

What regex for C# can I use that matches the a "string + some number + string + some number +string" Sample Inputs: Book a hotel room for 10 people -- o/p: 10 Book a hotel room for 15 people at ...
0
votes
2answers
38 views

How to highlight_string content from a form within tags pre using php

I have content that is posted from a WYSIWYG form with ajax where codes are placed between tags stuf before content <pre class="brush: php; light: true; collapse: true; fontsize: 500; first-line: ...
0
votes
1answer
25 views

Regex to block ? parameter in url

I have a pretty basic regex for a soundcloud link as follows: /^(https?:\/\/)?((www)?\.)?soundcloud\.com\/[a-zA-Z0-9]*/ It doesn't do much and I would like to block that kind of more complicated ...
1
vote
1answer
12 views

Use Regex to lookahead and redirect in case of match IIS

I have the following IIS rule which is supposed to redirect if the URI does not contain the word Api: <rule name="React Routes" stopProcessing="true"> <match url=".*" /&...
2
votes
3answers
56 views

Powershell Regex to match IP and two wildcards

I'm writing a small utility which requires user input of either IP address or hostname. I'd like to validate the IP address, which could contain the PS wildcards of '*' or '?' I've got this Regex so ...
0
votes
0answers
17 views

How to match string based on repetition of ith char? [closed]

I want to match string of the following type [*some pattern already matched*] *some text already matched*: *any specific char repeats here* I am not able to match the last part. Using /pattern/: .{...
1
vote
1answer
26 views

Input value contains specific characters anywhere

I have a directive that validates an input field to make sure it doesn't contain &, <, > .directive('refValidate', [function () { var regExp = /^[&\<\> ]*$/; return { ...
-4
votes
0answers
14 views

regex mac and windows [closed]

I've been trying to validate path files for windows and mac. For windows this regex works : ^[a-zA-Z]:\\[\\\S|*\S]?.*$ Does anyone know how to validate a macos path? Thanks for your help
2
votes
2answers
39 views

Regex to extract date and specific string

I have a a filename below and I want to extract year and _TEXT part. fle_2019-11-17A17-21-09.01(_TEXT).txt I am able to do this using two regex and then join the results. (?<=\_)(\d{4})(?=\-) ...
1
vote
1answer
23 views

Regex to match string with an optional part in the middle enclosed with spaces

I have these strings: /usr/bin/sudo argv sudo ssh /usr/bin/sudo argv ssh and I have to match both with the same expression. I mean, "sudo" string is an optional match which can exists or not. I ...
0
votes
2answers
21 views

Regular Expression: Only convert url “http|https” outside element

I have a string: http://localhost/xyz http://localhost/rpq http://localhost/abc <img src="http://localhost/xyz/image.png"> Now, I want to convert only: http://localhost/xyz http://localhost/...
2
votes
1answer
24 views

matching numbers after nth occurence of a certain symbol in a line

I'm not sure if using regex is the correct way to go about this here, but I wanted to try solving this with regex first (if it's possible) I have an edifact file, where the data (in bold) in certain ...
0
votes
0answers
20 views

Is it possible to match the Other language with English alphabet in C# [duplicate]

I need to match the other language letter with the English Alphabet. that means, the string "Gården" should be equal to "Garden" like that íūāōâã... as iuaoaa.... I tried str.Replace("ā","a").Replace("...
-2
votes
0answers
13 views

load a text file into data grid code and i want use regex delete the circle but Doesn't work as i want [closed]

textfile to datagrid else { List<code> codes = new List<code>(); string textfile = ofdl.FileName; ...
-2
votes
1answer
34 views

reg ex for searching filenames [closed]

I want to select the files, whose names ends with _90.jpeg|_180.jpeg|_270.jpeg|_90.jpg|_180.jpg|_270.jpg. currently I am using the following approach pattern = re.compile('_90.jpeg|_180.jpeg|_270....
-3
votes
0answers
15 views

Stop a RegExp lookahead if it encounters XXX [closed]

I've got a paragraph that contains text, some of which are anchor links. I want to pick out string matches that aren't enclosed in anchor tags but my negative lookahead string(?!.+\</a>) isn't ...
0
votes
2answers
36 views

Using Regex to Replace “margin” with padding inside HTML tags

I am currently working with Kendo UI for jQuery Editor. The issue that I have is to convert all the "margin" attributes (margin, margin-left, margin-right and so) assigned to a block element (assigned ...
-1
votes
0answers
15 views

regex storing data in a single list, cant decide ending criteria of regex re.findall [duplicate]

test = "http://example.com/afternoonhttp://bell.example.com/advertisement/base.phphttp://www.example.com/" i am trying to seperate these urls from the test string in python using regex the regex code ...
1
vote
4answers
83 views

Regex to find valid IP address using awk

I get all the IP address connected to the network along with strings and name of the network, but I wanted to extract only the IP's using awk regex I tried : awk '{match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[...