Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

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
7 views

Pushing regexmatches values out of if else statement

The end goal of this is to push regex matches into a MySQL database. When multiple files are being read of the program, I will take the regex matches and update to the database. However file details ...
0
votes
0answers
5 views

How to match strings using negative lookbehind with multilines?

I was trying to create some examples to understand a little better regex assertions with PRCE. //(?<=) - positive lookbehind $string = "dra Julia \ndr Marcos \ndr Mateus \ndra Ana"; $regex = "/(?&...
0
votes
1answer
11 views

Extracting and then combining Street Address and Apartment Numbers in pandas

I'm having a really challenging time coming up with the code needed to perform the below. There's a similar question with this but I can't figure out how to adapt the code to what my needs are ...
0
votes
0answers
6 views

Regex to match only book('knjiga') with specific name('naslov')

I have a simple xml: <?xml version="1.0" encoding="utf-8" ?> <book_list> <book rbr="1" > <title> Yacc </title> <author> Filip Maric </author&...
1
vote
1answer
18 views

Javascript to detect any wildcard url from certain domain (ex: google)

I am writing a simple if else if function. If prevPage contains any of 'accounts.google.com' redirect to homepage, else if not from 'accounts.google.com' redirect to login, as simple as that. I only ...
-3
votes
2answers
28 views

Regex for a number less than 1900 and greater than 2020

How to build a regex for a number less than 1900 and greater than 2020
0
votes
0answers
9 views

TCL line parsing with escape chars

An observation and question. Given a textfile with lines which include escape characters. I.e. backslash. Parsing those lines and separating content using lindex and lassign eat away the escape ...
-1
votes
1answer
25 views

Need a match of a string which has two of the same characters

Complete newbie to Regex, I need a regular expression which matches strings which start and end in the same character, and in between can be anything (even numbers) I've tried some things, but I can'...
0
votes
0answers
5 views

Splitting a stream with more than one consequtive delimiter including pipe [duplicate]

Spliting a stream containing "&|&" as delimiter I have a stream containing more than one element and using the following separator "&|&" String user="White, John&|&false&|...
0
votes
1answer
19 views

PowerShell - Import Text File and Filter

Requires: Import large tab delimited text file, varying from 3.5-5.5 million lines. Export only matching lines to a separate file. File Contents (does have tabs at end of line too): Id TypeId ...
-1
votes
0answers
9 views

not use negative lookbehind for matching a pattern in filename? [duplicate]

I need to match a 2 in filename.2.csv - I am using numbers immediately preceding extensions for versioning. Came up with this expression: (?<=\.)([0-9]*)(?=\.[\w\d_-]+$) Click here for sample in ...
0
votes
0answers
22 views

Java Regex match UTF-8 String (Without Copy)

I'm loading large UTF-8 text from a SocketChannel, and need to extract some values. Pattern matching with java.util.regex is great for this, but decoding to Java's UTF-16 with CharBuffer cb = UTF_8....
-1
votes
0answers
35 views

Select block of text and merge into new document

Hi I've looked online and just can't find the right answer. I have files which have <!--#start#--> and <!--#stop#--> through out them. I only want the contents between those two strings. ...
-1
votes
0answers
7 views

OpenOffice4 convert date/time/offset to date

I have data in this format: 2019-08-11 20:30:50 -0400. How can I convert it to just the date? The reason for converting is so I can enter a date in a second column and use a formula to populate a ...
0
votes
1answer
17 views

Notepad++ regular expressions: search string is spread over multiple lines

I have this question. I would like to locate certain functions in a script, but the functions are completed with a semicolon rather than an enter. So it could be: AsciiOutput( ... ); or: AsciiOu ...
0
votes
1answer
49 views

check if string matches first n characters of regex

I have a python site built in Django where a user will be uploading files that they may or may not have permission to add. The permissions are created through a series of regex patterns (there is over ...
-4
votes
0answers
17 views

Regular expression to match any file within the root directory and every file within the directory /public/ [on hold]

I'm trying to create an regex that matches the following I've an webapplcation. I need to match - any file within the root directory of the webapplcation and - every file within the directory /...
-1
votes
1answer
28 views

Check if first character of string is digit or whitespace with regex or alternative [duplicate]

I want to check if a given string's first character is a word character/not a digit or white-space and return a boolean. I'm trying to use regex for this. What I have is: function ...
1
vote
1answer
21 views

Insert embed code only in place of urls that are not in href

I am customizing a module on a drupal 8 website, where certain vimeo or youtube urls are converted into embedded iframe videos. The module itself works great, however a problem arises when there's a ...
1
vote
1answer
20 views

Regex expression to find value in string that has a static position but variable amount of characters

I am reading in data from a PDF, and the output is a block of text. The goal is to pull out one value from that block of text. The value I need to pull is in a static position, but the amount of ...
0
votes
0answers
28 views

How to use \u or \x in regular expression matching? (C#) [duplicate]

I couldn't figure this out after spending 2 days of Google search and trials. Question: Is there any way to use a regular expression that includes \u or \x? What I want to do: I am reading a long ...
0
votes
0answers
10 views

Having trouble including double quotes with RegularExpressionAttribute [duplicate]

Having trouble including double quotes in a group of acceptable characters in a Regular Expression. I have a Asp.Net MVC project with a model that has some string properties that I want to only allow ...
0
votes
0answers
25 views

Modifying regex to not allow spaces [duplicate]

I have this regex that matches any string that contains one or more letters followed by one or more numbers [A-Za-z].*[0-9] I'd like to modify this to not allow spaces, which looks like can be done ...
1
vote
0answers
54 views

How to convert regex Python to regex javascript

I wrote a regex python but I do not find how to convert to be compatible in javascript. I try with the table comparisons but it does not give me the equivalents or other possibilities.http://web....
0
votes
1answer
37 views

Capture strings inside escaped quotes

I have 3 strings in this format Bank: {"955974044748481":["BANK_A"]} {"reason": "Bank: {"455049295219902":["BANK_B"]}"} {"reason": "Bank: {\\"1876212592475597\\":[\\"BANK_C\\"]}"} I need to extract ...
0
votes
2answers
43 views

How to capture all lines between two lines in regular expressions with ruby? [on hold]

Suppose I have the following text: 0000000000401040 <[email protected]>: 401040: ...
1
vote
0answers
21 views

How do I replace the nth occurence of a match when using Look Ahead and Look Behind Regex pattern

I'm looking for a way to do a replacement of some image paths in code using regex function. Ultimately, I'll be using a text batch processing tool called "TextCrawler" to do these substitutions but ...
-1
votes
1answer
25 views

Extracting paragraphs within section headings [on hold]

I have text (read in through readtext) that looks like this: First Summary of Lorem Ipsum Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the ...
-1
votes
1answer
30 views

pgrep multiple process names

I want to get PIDs of two or more processes using "pgrep" command in Linux. As we know pgrep syntax is pgrep [options] <pattern> Here is a hypothetical command which should return PIDs of ...
-1
votes
4answers
32 views

Regex matching a set of characters on a given index

I have a string and a position in this string. I want to find out if the last non space character before this position is one of the characters in a given set. Can I do this using regex? I couldn't ...
0
votes
1answer
20 views

Cannot increment returned sregex_iterator?

I'm trying to construct an sregex_iterator from some complicated computations so I wrote a function to do this and return the iterator. However when I then want to increment the returned iterator, the ...
1
vote
2answers
27 views

RegEx match anything except linebreaks up to positive lookahead

I'm trying to match certain text lines up to a specific string in RegEx (PCRE). Here's an example: 000000 999999900 20.10.19 Amoxicillin 1000 Heumann 20 Filmtbl. N2 - PZN: 04472730 - Dr. Max ...
0
votes
2answers
54 views

How to extract multiple strings between two words

I am using powershell to get the contents of a log file. I am trying to extract an unknown string between two known words. I need to do this for multiple lines so i want multiple strings searched ...
0
votes
2answers
29 views

Python regex to replace any characters that are not either letters or white space

I'm trying to replace all non-letters and non-whitespaces with ''. I thought the below code worked fine in a number of test cases, however, it failed when it comes to special, escaped characters. ...
-4
votes
1answer
34 views

Removing parentheses at the beginning of string

I want to remove text in parentheses which is only before the string like: (bc2) xxxx. How I can do this using regex?
-1
votes
4answers
50 views

Ignore any spaces before or after a name in R [duplicate]

In data.frame dat there are two sets of names under variable Name: bob an jim. But, some of these names may have some spaces either before (ex:" jim") or after (ex:"bob ") them. I was wondering how I ...
0
votes
1answer
24 views

How do I enforce total character count in regex?

Suppose I have a string of numbers whose length is 4. const example = "1234"; I need to verify the following patterns are all valid: 1-2-3-4 1234 12-34 1-234 123-4 I'm setting my first and last ...
-1
votes
1answer
21 views

Regex is stripping out period at the end of sentence it should keep the period

here is my regex: alert(data.data.Message.replace(/<[^>]*>/g, ' ') .replace(/\s{2,}/g, ' ')).trim(); It is being used to strip out html tags. in this image you can see what the regex is ...
-1
votes
0answers
10 views

Regex Coding Issue [duplicate]

Attempting (and failing) to create a regex experssion to match a pattern like this: 6y9 p0p Currently coded (and not working): ^([a-zA-Z0-9]{3})([_]{1})([a-zA-Z0-9]{3})$ Previous attempts & ...
-1
votes
1answer
16 views

Javascript Regex constructor to match string, and ignore null, undefined, or empty strings

I'm trying to add regular expressions to only match non-null values. What I've tried below breaks the application as there are some names, ages, and genders that are undefined and null in the database....
0
votes
1answer
24 views

regex pattern not working properly in iOS [duplicate]

I'm doing client side validation for a website and there's this bug... Using this regex: /^(?!-)[a-zA-Z0-9\-]{1,20}(?<!-)$/ I'm trying to block special characters from being used in the input ...
1
vote
4answers
50 views

Regex to retrieve last digits from a string and sort them

I have a list of string which I want to sort them using the last digits present in the string, I have tried this using below code, but for some reasons, it's picking digit present before the last ...
0
votes
1answer
9 views

how to parse dynamic logs using grok and logstash?

I 'm new in logstash and grok and trying to parse logs that look like this: 2019-10-23 08:44:38.457 INFO 99999 [ID1=645ae2ae-a9a6-412f-b079-f0495aa9b713, ID2=62702, ID3=3e37ee7c-4e09-4924-be2f-...
0
votes
3answers
52 views

Find something that does not match a pattern at the beginning of line

I am using regex in Python to find something at the beginning of line that does not match pattern "SCENE" and before colon. The text looks like this SCENE:xxxxxxdd\nAQW:xxxxxdd\nSCENE:xxxxxdf\nCER:...
0
votes
2answers
40 views

How to validate binary fraction with regex?

Currently, I'm using regex [^0-1] to limit the binaryValue input with only 1's and 0's using find() in Matcher class. String binaryValue = "10", strRegex = "[^0-1]"; Pattern p = Pattern.compile(...
1
vote
1answer
23 views

Do hashtags interfere with lookaheads in a regex?

I've tried to capture some data in between a lookbehind and a lookahead. My test string: #2000 STEPS OF EQUILIBRATION AT LAMBDA 0 COMPLETED #STARTING COLLECTION OF ENSEMBLE AVERAGE TI 2000 0.0000 0....
0
votes
0answers
15 views

Escape all characters apart from forward-slashes and alpha-numeric characters in URL parameter

I have a page on my website that uses Razor to take a URL parameter from a C# model and assign it to a href in an onclick event, like so: <input type="button" class="button" onclick="location.href=...
0
votes
0answers
9 views

WordPress add_rewrite_rule confusion

I thought I wanted something fairly simple. Catching all the url's containing /s/, and rewrite them. But for some reason my query vars do not contain the first match. Making it match multiple tags ...
0
votes
2answers
24 views

Regex with negative lookahead does work with zero or more preceeding whitespaces

I'm trying to understand how to make negative lookahead get executed after the series of \s*:?\s*. Right now it leads to unwanted matches, so I'm forced to use \s*:?\s+, but it doesn't cover some ...
1
vote
2answers
14 views

Find characters of a set with a leading OR trailing whitespace

I want to write regex to match a set of characters that are proceeded or succeeded by a whitespace or other space character So far I have ((?<=[\s\S])|(?=[\s\S]))[^\s\p{L}\p{N}]+ However in the ...