Questions tagged [regex-lookarounds]
Regular expression lookarounds are zero-width assertions that verify conditions about the context of a match at the current match position.
3,295
questions
2
votes
2
answers
69
views
How can I capture only the beginning and end of a string, while avoiding the middle of a matched regex?
I am trying to capture the very beginning and the very end of a matched regex with a grep command, but I don't want the middle of the string to be captured.
Here is the string:
href="file:///home/...
0
votes
1
answer
17
views
Avoid dot on ElasticSearch/OpenSearch
I am new with ElasticSeach, and currently working with OpenSearch from AWS OpenSearch service. In Dev Tools, I have the following query:
GET _search
{
"from": 0,
"size": 10,
&...
0
votes
0
answers
29
views
Unexpected regex result using word boundary and asterisk character [duplicate]
I am testing some regex patterns for a project I'm working on.
In one of the patterns I am trying to match the input "f**" and "f**xxx" meaning literally "f**" followed ...
0
votes
1
answer
44
views
How prevent catastrophic backtracking with multiple negative lookaheads
I have a dataframe with strings in one column. I would like to add the words 'section 22' to a string when it contains the word 'personal information'; at the same time, I would like the section 22 ...
1
vote
2
answers
91
views
Regex capturing too much
I have a problem with a .NET regex that I need to create for my AutoWikiBrowser bot on Wikipedia.
The example is rather long, but I need an even longer regex to find up to 14 language indication ...
1
vote
1
answer
53
views
Regex for removing duplicate values in a specific Wikipedia template
I am trying to remove duplicate values in a Wikipedia template (and only in this one) with a regex using the AutoWikiBrowser bot (that works with the .NET flavour).
I want to find {{mul|fr|en|fr}} and ...
-1
votes
0
answers
20
views
regex positive lookahead placed before some text [duplicate]
^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$
I found this regular expression to check if a string contains both numbers and letters (at least 1 number and 1 letter). Examples for positive lookahead all ...
-1
votes
1
answer
58
views
Regular expression : How to match a specific word with having spaces and with an additional letter in the starting or ending?
Im trying to do something fairly simple with regular expression in php
What i want to do is matching words from a string no matter wherever that same character is. If its at the beginning of the ...
0
votes
2
answers
89
views
How do you write a Regex that combines a Negative Lookbehind with a Negative Lookahead to create a Negative Lookaround?
In our Java Selenium framework, we need to write a regex that reads a string of any length and returns true if it contains the substring "bar" so long as the substring "foo" doesn'...
-2
votes
2
answers
84
views
Two consecutive positive lookaheads fail but each individually succeeds [duplicate]
I am trying to write a regex in the Java 8 flavor that looks for two different static strings to occur in a multiline text file in any order. I have a regex that works in other circumstances, but not ...
1
vote
2
answers
57
views
regex: negative lookahead with multiline text
I have several files with text blocks like that:
maxlength:
maxlength_js: 500
maxlength_js_label: 'Inhalt auf @limit Zeichen begrenzt, verbleibend: <strong>@remaining</strong>'
...
-3
votes
1
answer
55
views
Capture a string of digits from within two strings
I am trying to capture a string of digits from within a string of data. The digits I'm trying to capture starts with 109 and is followed by a space, 2 digits, a comma, and a space.
I'm trying to ...
1
vote
2
answers
105
views
Finding last occurrence of a pattern with lookaround
I have the path ../dir1/dir2/dir3/filename.txt and want to extract just filename between the final \ and . using regex. The file extension will also not always be .txt.
Currently I am doing (?<=\/)....
2
votes
2
answers
57
views
Regex matching a string in a filename while excluding another string
I am using regex to search through folders to find files that match on certain strings, but I also need to exclude other strings. For example, in the paths below I need to return a match for the ...
-3
votes
1
answer
79
views
How To Un-CamelCase Part Of A String?
I have long markdown lists of images like:

I want to un-CamelCase the caption but not the filename
to get this result:
.+$
And if I ...
0
votes
4
answers
91
views
How to match these string variations in regex?
The question is pretty straightforward, I want to process a string using regex compiler in Go, and break it apart into three substrings. I already have something that works but sadly it has some ...
1
vote
3
answers
58
views
Regex to extract multidimensional keys using bracket notation
I need to retrieve all keys using pure regex.
I need to start with word field and after that need to capture all multiple keys..
field[somevalue][anothervalue]
I'm using this regex:
/^field(?=\[(\w+)](...
0
votes
1
answer
70
views
look for strings which are starting with . do not contain a . and end with _ any character : then any character
I have strings like this:
fd.s_fdsfds.na233_OVERFLOW:fdsfdsfds
fds_f.dsfds.cs194_0.0-1000.0:fdsfds
fdsf.dsfds.abc333_0.0-1000.0:fdsfds
I want to match na233 & cs194 & abc333
so far I came up ...
1
vote
1
answer
36
views
Regex that matches files with two or more unique extensions
I am trying to create regex that matches files with two or more extensions, but I want to ignore duplicate extensions.
Examples of results I want:
videogame.exe.exe - Don't match
unknown.pdf.exe ...
0
votes
2
answers
89
views
Regex to find all class names from .css file
I am working on a ticket for an open source project. There are over 800+ css files, and I need to get all the class names from all these files, and then check all the HTML files for these class names. ...
1
vote
1
answer
31
views
Regex match string but do not match when containing certain elements
I am trying to make a regex match with a series of similar strings but not match others that meet another certain criteria. I almost got it right but am having trouble when trying to exclude certain ...
-1
votes
1
answer
68
views
Python regex to match string not preceded by another string, but with other words in between
I tried the accepted answer to Regex match word not immediately preceded by another word but possibly preceded by that word before but that didn't work.
>>> re.search('(?<!nonland) onto ...
1
vote
1
answer
47
views
Regex non-capturing group being mind for captures
I have this regex statement:
&logline=(?:.*?\[Pipeline\]|\[[\d-]+T[\d:.]+Z\])?.*?(\[)
I want it to skip over .*?\[Pipeline\] and \[[\d-]+T[\d:.]+Z\] (if they exist) and then find the a bracket ...
0
votes
2
answers
57
views
Regex pattern print group1 and group2
I'm new to using regular expressions here, when I'm trying to extract a content after a string match but the result I'm getting is from Group1
Regex Pattern : ("Method":)(?s)(.*$)
String: I'...
0
votes
1
answer
39
views
Regular expression: lookahead assertion not works as expected with lookbehind assertion
I’m trying to create a regular expression that can identify a sentence within a text that contains a specific word - ‘JavaScript’ in this case. My approach is to extract the part of the text preceding ...
1
vote
1
answer
47
views
Regex to match a symmetric (palindromic) text pattern [duplicate]
I am trying to match a string of the form:
itrti
ititrtiti
itititrtititi
but not
itrtiti
ititrti
where the length of the pattern on either side of the 'r' is the same.
I can write (I think):
(it)+r(...
4
votes
4
answers
111
views
Match only if following string matches pattern
I'm trying to match an entire string that starts with a certain string and then match any number of characters except ::, if :: was matched then only accept if followed by the string CASE.
So for ...
0
votes
2
answers
44
views
Checking specific Regexp that can contain up to 3 keys made by letters and numbers and separated by comma, but not only zeros
I need help checking my Regexp.
Context:
I have a script that takes an Excel file as an input to import products in a DB, there's a special field that takes "extra keys" for the product, the ...
2
votes
5
answers
87
views
Regex to match only the second ip address in a range
I'm trying to match only the second valid ip address in a string with a range of ip addresses. Sometimes it's written without a space between addresses and something it has one or more spaces. Also ...
0
votes
1
answer
46
views
Python regex to match pattern if not in double quotes or equal to list of keywords
I have a regex pattern which represents a valid variable name in a language I'm trying to parse:
R'\b([A-Z][A-Z0-9_]{0,35}\b' (e.g. VAR_NAME, TABLE_READ, SOME_OTHER_VAR etc..)
However, I don't want to ...
-1
votes
1
answer
44
views
How to regex match strings that do not contain a set of substrings [duplicate]
I am looking through 1000s of JSON files, and all of them have a property on them like this: "value": {some number},
I want to grep all of these JSON files, and match all cases where value ...
0
votes
1
answer
38
views
Regex to rename multiple files at the same time
I'm trying to use regex to rename my header files. I could have easily manually changed the files but it's been hours and I've been wrecking my brain trying to figure it out.
I have 3 things I want to ...
2
votes
1
answer
49
views
Capturing negative lookahead
I need for https://github.com/mchelem/terminator-editor-plugin to capture different type of path with line number. So far I use this pattern:
(?![ab]\/)(([^ \t\n\r\f\v:\"])+?\.(html|py|css|js|txt|...
2
votes
2
answers
64
views
Regex - Match a word but do not match a phrase that can appear anywhere in the phrase
I have been spending time on this regex but I can't get it to work. So I need to match bunch of words in a phrase but if the same word occurs with a set of words, I do not want that to be captured. ...
0
votes
1
answer
54
views
Not able to figure-out where I am making a mistake
I have one data frame column dtc_mined which contains value like below seperated by |
P18A253|P18A0|P18A2|P18A043|P2B61
here it contains some values some of its length is 5 (P18A2) or some of its ...
1
vote
1
answer
30
views
Is there a way to reliably find what modules would be loaded if a string were run as code in Python 3?
I am writing a script to search data provided by users may contain Python code which may be calling modules. I am able to retrieve the code as a string, but I need a reliable way to determine what ...
0
votes
1
answer
42
views
Regular Expression: Ensure that if a string contains specified symbols, then they must be enclosed by
My regular expression needs to ensure that:
It consists of letters, so this can be done with:
^[a-zA-Z]+$"
[Question] The string also can contain dot(s) and/or comma(s) and/or hyphen(s) and ...
0
votes
1
answer
67
views
Searching unescaped ampersands in a pseudo XML file on Neovim with negative lookahead
I don't know how to transform / the equivalent of this negative lookahead search on Neovim.
&(?!(?:apos|quot|[gl]t|amp);|#)
When I try silver search, it is working. I want to search but only on ...
-1
votes
3
answers
69
views
How can I achieve this regex without a look ahead assertion?
I have regex which uses a look ahead assertion to match strings of the format {{ x }}. The regex is /(?<=\{\{\s)[^}\s]+(?=\s*\}\})/gm
How can I achieve this without using a look ahead assertion?
1
vote
1
answer
45
views
How do I exclude a pattern with a lookbehind that is in front of another pattern?
How do I not capture or detect matches if the regex pattern precedes this regex pattern r"(?<=\s)|^)dont\s*"
This is the pattern that you want to use to exclude matches. It correctly ...
1
vote
2
answers
56
views
Match multiple regex groups starting after a specific word/pattern within the text
I'm trying to match all instances of a percentage (e.g. 20%) AFTER a specific pattern (or in this case a word):
Lorem ipsum dolor 10% sit amet, consectetur adipiscing elit. Morbi et
feugiat Discount ...
0
votes
2
answers
57
views
Regex match only if not in context
Engine: Vim RegEx
Input:
\begin{thoerm}\label{ABC_for_all}
If the ABC is a common good, $ABC(places)$ includes everything.
\end{thorem}
We will now prove Threorem \ref{ABC_for_all}.
Expression:
(...
2
votes
1
answer
39
views
Regex pattern that ensures that atleast one character is present along with other conditions
I am trying to validate a string based on the three conditions below
It must contain a string
It should not contain any special characters except . and -.
Numbers are allowed but not necessary
I ...
2
votes
1
answer
146
views
Regex help for git commit messages
I want to create a regex to enforce git commit messages. The styles are as follows:
<type>(<scope>): <subject>
<body>
BREAKING CHANGE: <breaking>
Refs: <references&...
-1
votes
1
answer
71
views
Python Regex findall() returning empty keys
I'm trying to capture a couple of groups messages in a text with regex findall() but I always end up with empty values in the capture, that are not present if I use every single regex pattern ...
1
vote
2
answers
60
views
Regex For Report Section Headings and Subheadings
Edited with corner cases.
I need to write a regular expression that can match section heading and subheading from a PDF file the one below. Headers are a number followed by a period and then a title ...
2
votes
2
answers
39
views
PCRE regex to match next occurrence of specific pattern or EOF
I have a file with following content:
#### v2
START MATCH
Text explaning things and stuff.
This has to be matched.
END MATCH
#### v1
Do not match this part (or anything
below "END MATCH"...